STL for C++s
The STL is the part of the C++ standard library built on containers, iterators and algorithms. Containers such as vector, map and unordered_map store data, iterators give uniform access to elements, and algorithms like sort, find and transform operate on iterator ranges. Using them replaces hand-written loops with tested, efficient code.
Stage: Standard Library · Part of the C++ roadmap · Last reviewed 19 November 2026
What to learn in STL
- Choose between vector, deque, list, map and unordered_map for a task
- Iterate with iterators and know which operations invalidate them
- Sort and search with std::sort and std::lower_bound
- Transform and accumulate data using algorithms and lambdas
- State the time complexity of common container operations
STL interview questions
When would you choose std::map over std::unordered_map?
Use map when you need keys kept in sorted order or need range queries, at logarithmic cost per operation. Use unordered_map for average constant-time lookup when order does not matter and the key has a good hash function.
What is iterator invalidation?
It happens when an operation makes existing iterators, pointers or references into a container unusable. For example, a vector push_back that reallocates invalidates all of them. Using an invalidated iterator is undefined behaviour, so check the container's rules.
Where STL fits in the C++ roadmap
STL belongs to the Standard Library stage (advanced level), which takes about 37 hours. Containers and algorithms.