Hacker News new | past | comments | ask | show | jobs | submit login

I was recently faced with this (luckily I realized it before coming across any strange bugs), and realized std::deque works great for this if you don’t need random access (which was fine for my use-case because I just grabbed references immediately after insertion).



std::deque has O(1) access by index so it's fine for random access (although it has some extra indirection so it's still slower than vector)


It's O(1), for high values of 1.


Wow I was literally reading the docs last night and didn’t notice operator[]! Good to know




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: