First, container classification:
(1) Standard STL sequence containers: vector, String, deque, and list.
(2) Standard STL associated containers: Set, Multiset, map, and multimap.
(3) Non-standard sequence containers slist and rope. Slist is a one-way linked list, and rope is essentially a heavy string.
(4) non-standard associated containers hash_set, hash_multiset, hash_map, and hash_multimap.
Next, how to choose a more appropriate container:
(1) If you want to insert a new element anywhere in the container, it is more appropriate to select a sequence container.
(2) If we care about the order of elements in the container, avoid using a hashed container.
(3) If you want to randomly access the iterator, it is technically limited to vector, deque, and string.
(4) If we care about the search speed, we should first consider using the hash container, then the sorted vector and the standard associated container.
(5) If we care that the bottom layer of the container uses reference count, we should avoid using it as much as possible. Its underlying implementation is implemented by reference count.
We can consider replacing string with vector <char>.
(6) If you need to support multi-element insertion, you should select list, because list is the only standard container that provides multi-element insertion of transactional semantics.
(7) If you need a sequence container with the following features: 1) You can use a random access iterator; 2) as long as it is not deleted and insertion only occurs at the end of the container, the pointer and referenced data will not expire, so deque is the ideal choice at this time.
Compared with vector, deque also supports inserting data from the start end: push_front ().