Core · Module 7
STL Containers and Algorithms
Choose the right standard container, iterator, value type and algorithm, then compose them into predictable data-processing programs.
The standard library already implements the containers that the earlier MyVector and MyString examples reimplemented by hand. This module teaches you to reach for those tools first: what guarantees each container makes, what each operation costs, how iterators and ranges connect them, and how a complete data-processing program combines validation, indexing, algorithms, aggregation and reporting.
- 1vector: The Default Container and How It GrowsPro — members onlyStore a growing sequence in contiguous memory, understand doubling growth and amortized cost, and never invalidate an iterator by accident again.10 min
- 2string: Characters, Storage and Small-String OptimizationPro — members onlyStore text without manual new and delete, compare size, capacity and null terminators, and predict when small-string optimization avoids the heap.10 min
- 3Sequence Containers and Adaptors: Choosing the Right ShapePro — members onlySelect array, deque, list, forward_list, stack, queue or priority_queue from their access, ownership and complexity guarantees.13 min
- 4Associative Containers: map, set and unordered_mapPro — members onlyPick ordered versus hashed lookup for the catalogue, compare O(log n) tree cost against average O(1) hashing, and use map, set and unordered_map without surprises.9 min
- 5Classic Algorithms: Predicates, Iterators and Output RangesPro — members onlyReplace repetitive loops with tested search, copy and ordering algorithms, then state the iterator and predicate guarantees each call requires.11 min
- 6Iterator Categories, Invalidation and RangesPro — members onlyMatch algorithms to iterator capability, reason about lifetime and invalidation, and bridge classic iterator pairs with C++20 ranges.12 min
- 7Algorithm Families Beyond Sort and FindPro — members onlyUse modify, erase, partition, heap, binary-search, set, numeric, min/max and permutation algorithms with their real preconditions and costs.15 min
- 8Modern Standard-Library Tools: optional, variant, span and rangesPro — members onlyRepresent absence and alternatives safely, pass contiguous data without ownership, and compose algorithms with C++20 ranges.12 min
- 9STL Value Types: pair, tuple, array, string_view, bitset and numeric_limitsPro — members onlyCarry small structured values, borrow text safely, represent fixed bits, and use numeric_limits to make boundaries explicit.12 min
- 10Filesystem, Time and FormattingPro — members onlyUse standard-library types for paths, durations and formatted output instead of fragile strings and ad-hoc clocks.11 min
- 11Project: Library Inventory and AnalyticsPro — members onlyBuild a validated C++20 inventory pipeline that ingests records, maintains indexes, removes duplicates, partitions stock, and produces searchable analytics.18 min