← C++ Programming learning pathC++ Programming · Module 7 of 10
Templates and the STL
Write generic code and use standard containers.
📖 Key ideas
- Templates: template <typename T> T maxOf(T a, T b).
- STL containers: vector, list, deque, set, map, unordered_map, stack, queue, priority_queue.
- Iterators traverse containers.
- <algorithm>: sort, find, binary_search, reverse, count.
- 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