I will be the second (or maybe the third ...) opinion that std::vector or std::deque will do the job. The only thing I will add is a few additional factors that should determine the solution between std::vector<T> and std::list<T> . They have a lot in common with the T characteristics and the algorithms you plan to use.
Firstly, this is the memory overhead. Std::list is a node-based container, so if T is a primitive type or a relatively small user type, then the node-based memory overhead may not be significant - consider that std::list<int> is likely to use the storage is at least 3 * sizeof(int) for each element, whereas std::vector will use the storage sizeof(int) with little overhead at the top level. std::deque is similar to std::vector , but has a little overhead that is linear up to N
The next question is the cost of building a copy. If T(T const&) generally expensive, then avoid std::vector<T> , as this leads to multiple copies appearing as the size of the vector increases. Here std::deque<T> is the clear winner, and std::list<T> also the contender.
The final problem that usually determines the decision on the type of container is whether your algorithms can work with the annulment restrictions of the std::vector and std::deque iterator. If you manipulate the elements of the container a lot (for example, sorting, pasting in the middle or shuffling), you can lean towards Std::list , since order management takes a little more than resetting a few binding pointers.
source share