Ready-made containers and algorithms you will use every day. Learn it alongside OOP.
Introduction to the STL
Intermediate · Stage 5: Standard Template Library
The STL is three pieces that work together: containers store data, iterators walk through it, algorithms process it.
After this: Know which part of the library to reach for and where to look it up.
std::vector
Beginner · Stage 5: Standard Template Library
A dynamic array that grows as you add elements. It's the default container to reach for.
After this: Use push_back, size, indexing and range-based loops with vectors.
std::string
Beginner · Stage 5: Standard Template Library
std::string as a container: find, substr, insert, erase and conversions to and from numbers.
After this: Process and transform text with standard string operations.
std::pair
Beginner · Stage 5: Standard Template Library
Holds two values together (.first and .second). It's often returned from functions and stored in maps.
After this: Group two related values without writing a struct.
std::list
Intermediate · Stage 5: Standard Template Library
A doubly linked list: fast insertion and removal anywhere, but no indexing and poor cache locality.
After this: Know when std::list is the right choice and when vector is better.
std::map
Intermediate · Stage 5: Standard Template Library
Sorted key-value pairs with O(log n) lookup, insertion and removal.
After this: Count, group and look up data by key in sorted order.
std::unordered_map
Intermediate · Stage 5: Standard Template Library
A hash table: average O(1) lookup, with no ordering of keys.
After this: Choose between map and unordered_map for a task.
std::set
Intermediate · Stage 5: Standard Template Library
Stores unique values in sorted order.
After this: Remove duplicates and check membership quickly.
std::unordered_set
Intermediate · Stage 5: Standard Template Library
Unique values in a hash table: average O(1) membership checks, no order.
After this: Pick the right set for the job.
std::stack
Beginner · Stage 5: Standard Template Library
std::stack: last in, first out (LIFO) with push, pop and top. Built on top of another container.
After this: Use a stack for undo, bracket matching and depth-first work.
std::queue
Beginner · Stage 5: Standard Template Library
std::queue: first in, first out (FIFO) with push, pop and front.
After this: Use a queue for scheduling and breadth-first work.
std::deque
Intermediate · Stage 5: Standard Template Library
A double-ended queue: fast insertion and removal at both ends. std::stack and std::queue use it by default.
After this: Use a deque when you need both ends, such as for sliding windows.
Iterators
Intermediate · Stage 5: Standard Template Library
Objects that point into a container. begin() and end() connect containers to algorithms.
After this: Loop with iterators and understand why some operations make them invalid.
STL Algorithms
Intermediate · Stage 5: Standard Template Library
sort, find, count, binary_search, accumulate and more, ready-made and well tested.
After this: Replace hand-written loops with standard algorithms.
Lambdas
Intermediate · Stage 5: Standard Template Library
Small anonymous functions written inline. They're ideal for custom sort orders and predicates.
After this: Write lambdas with captures and pass them to algorithms.
std::priority_queue
Intermediate · Stage 5: Standard Template Library
A container adaptor that always hands you the largest element first, or the smallest with std::greater. It is a heap underneath.
After this: Repeatedly take the best item, as in Dijkstra's algorithm or task scheduling.
std::tuple
Intermediate · Stage 5: Standard Template Library
Groups any number of values of different types. Structured bindings unpack it: auto [a, b, c] = t;
After this: Return several values from a function cleanly.
std::bitset
Intermediate · Stage 5: Standard Template Library
A fixed-size sequence of bits with fast bitwise operations, counting and printing.
After this: Store and manipulate flags or small sets compactly.
std::optional
Intermediate · Stage 5: Standard Template Library
Holds either a value or nothing, so a function can report "no result" without magic values like -1 (C++17).
After this: Return a value that might be missing, safely.
std::variant
Advanced · Stage 5: Standard Template Library
A type-safe union: it holds exactly one of several types, checked with std::visit or std::holds_alternative (C++17).
After this: Model a value that can be one of a few different types.
Numeric Algorithms
Intermediate · Stage 5: Standard Template Library
The <numeric> header provides std::accumulate, std::iota, std::partial_sum, std::gcd and more for working with sequences of numbers.
After this: Sum, fill and combine ranges of numbers without hand-written loops.