C++ STL Containers Selection Flowchart

Ebrahim Bararian
2 min readNov 15, 2018

Some days ago, one of my friends asked my opinion about this topic on Stack Overflow. After checking the mentioned post on Stack Overflow, I tried to redesign the flowchart suggested there. Here is the result:

STL Container Selection Flowchart (The Image with Better Quality)

In this flowchart, green arrows show yes response and the red ones show no response to the question in the yellow diamonds.

Why did I redesign the flowchart?

Here are the reasons why I decided to redesign the flowchart:

  1. I think STL containers are devided to 2 main classes. The basic containers and those leverages the basic containers to implement a policy. For instance stack leverages the deque container to implement the LIFO policy. Here deque is the basic container. The flow of the flowchart should go in a way that first separates the main basic containers and then those leverages the basic ones. The basic containers are vector, array, red black tree, list and hash table. Extended containers are stack, queue, heap tree (priority_queue), map, multimap, unordered_map, unordered_multimap, set, multiset, unordered_set and unordered_multiset.
  2. At first the flowchart should divide the decision process to the main situations we should decide on and then elaborate on each case.
  3. Some extended containers have the possibility of choosing different basic container as their inner container. The Flowchart should consider the situations in which each of the basic containers can be used. For instance, the priority_queue uses vector as its default container. But when we want to have large elements in the priority_queue and the memory of the inner vector is used completely, the vector needs to reallocate bigger memory and copy the elements into the new allocated memory. If we use deque as the inner container, the problem gets solved. And in another scenario that memory deallocation is important, it is good to use deque again.

--

--