← C++ Programming learning path
C++ Programming · Module 7 of 10

Templates and the STL

Write generic code and use standard containers.

📖 Key ideas

  1. Templates: template <typename T> T maxOf(T a, T b).
  2. STL containers: vector, list, deque, set, map, unordered_map, stack, queue, priority_queue.
  3. Iterators traverse containers.
  4. <algorithm>: sort, find, binary_search, reverse, count.
  5. Choose containers by needed operations.
💡 Real-life example: The STL is a well-stocked toolbox: pick the container that fits the job.
TemplateGeneric code for many types
std::mapSorted key-value container
unordered_mapHash-based key-value container
IteratorObject to traverse containers