Augusto KhaoticMind da Silva wrote:
I'd go with a std::list.
If you know how many elements you have from the begining than
std::vector can be a good option, since all memory would be
preallocated and the element access would be in a constant time.
If thats not the case, then i'd stick with a list, since vectors would
add some resizing overhead, when you add one element more than their
capacity.
std::list should be your last choice. In general, it gives you the
worse access performance.
std::vector should be your default and preferred container to use, if
you're only adding and removing from the end of the container.
If you're adding and removing from the beginning and from the end of
the container, then use std::deque.
Only use std::list if you're adding and removing from the center of the
container.
Moreover, even if you're adding and removing from the center of the
container, experts like Herb Sutter, still recommend to consider using
std::vector if you're only infrequently adding/removing from/to the
center.