Don't Reinvent the Wheel - Use Battle-Tested Tools
This module covers the third layer of the first-principles C++ learning path: The Toolbox.
After understanding memory control and zero-cost abstractions, you learn how to leverage the massive, optimized C++ ecosystem - the Standard Library and modern language features.
After completing this module, you will understand:
- STL Containers - When and how to use each container
- STL Algorithms - Write loops once, reuse everywhere
- Iterators - The glue between containers and algorithms
- Modern C++ Features - auto, lambdas, ranges, modules
- Compilation Process - From source to executable
- Tool Ecosystem - Build systems, package managers, tooling
03_toolbox/
├── 01_stl/ # Standard Template Library
│ ├── 01_containers/ # vector, map, set, etc.
│ ├── 02_algorithms/ # sort, find, transform
│ ├── 03_iterators/ # Iterator categories and usage
│ └── 04_functional/ # Lambdas, function objects
│
├── 02_modern_features/ # C++11/14/17/20/23 features
│ ├── 01_auto_type_deduction/ # auto and decltype
│ ├── 02_range_for/ # Modern iteration
│ ├── 03_lambdas/ # Anonymous functions
│ ├── 04_tuples/ # Multiple return values
│ ├── 05_optional/ # Optional values
│ ├── 06_variants/ # Type-safe unions
│ ├── 07_string_view/ # Non-owning string references
│ ├── 08_concepts/ # C++20 constraints
│ ├── 09_ranges/ # C++20 ranges library
│ └── 10_modules/ # C++20 modules
│
├── 03_compilation/ # Build & Tooling
│ ├── 01_cmake_basics/ # CMake fundamentals
│ ├── 02_build_systems/ # Make, Ninja
│ ├── 03_linking/ # Static vs dynamic linking
│ ├── 04_optimization/ # Compiler flags
│ ├── 05_debugging/ # GDB, sanitizers
│ └── 06_package_managers/ # vcpkg, Conan
│
└── README.md # This file
Focus: Learn to use the tools millions of developers have optimized
Topics Covered:
- Sequence containers:
vector,deque,list,forward_list,array - Associative containers:
map,set,multimap,multiset - Unordered containers:
unordered_map,unordered_set - Container adapters:
stack,queue,priority_queue - Choosing the right container - Performance characteristics
- Non-modifying:
find,count,search,equal,mismatch - Modifying:
copy,move,transform,replace,fill - Partitioning:
partition,sort,nth_element - Sorting:
sort,stable_sort,partial_sort - Numeric:
accumulate,inner_product,adjacent_difference
- Iterator categories (input, output, forward, bidirectional, random access)
- Iterator traits and operations
- Const iterators vs regular iterators
- Reverse iterators
- Custom iterators
- Lambda expressions and captures
std::functiontype erasurestd::bindand placeholders- Function objects (functors)
- Predicates and comparators
Key Questions Answered:
- Which container should I use for X?
- Why is
std::vectorfaster than arrays in other languages? - How do I write algorithms that work on any container?
- What's the difference between
std::sortandstd::list::sort?
Focus: Language features that make C++ modern and expressive
Topics Covered:
autokeyworddecltypespecifierdecltype(auto)for return types- Template argument deduction guides
- When to use
autovs explicit types
- Modern loop syntax
- Custom iterators for range-for
- Initialization statements in range-for
- Ranges views (C++20)
- Lambda syntax and captures
- Capture by reference vs value
- Generic lambdas (C++14)
constexprlambdas (C++17)- Lambda as comparator
std::pairandstd::tuple- Structured bindings (C++17)
std::make_tuple- Tuple cat and transformation
- Multiple return values
std::optionalfor optional values- Avoiding sentinel values
- Monadic operations (
and_then,or_else,transform) std::expected(C++23)
std::variant- Type-safe unionsstd::visitpatternstd::getand access- Recursive variants
- Sum types
std::string_viewfor non-owning references- Avoiding string copies
std::stringvsconst char*vsstd::string_view- Lifetime considerations
- C++20 concepts explained
templateconcepts- Constrained templates
- Standard library concepts
- Better error messages
- C++20 ranges library
- Range views (
filter,transform,take) - Range algorithms
- Pipelining operations
- Lazy evaluation
- C++20 modules vs headers
- Module import/export
- Build system implications
- Migration from headers
Key Questions Answered:
- How do I write modern, readable C++?
- What features replace old C-style patterns?
- How do I avoid boilerplate code?
- What are the performance implications of modern features?
Focus: Understanding and controlling the build process
Topics Covered:
CMakeLists.txtstructure- Targets and properties
- Finding packages
- Cross-platform building
- Best practices
- How compilation works
- Make and Ninja generators
- Incremental builds
- Parallel compilation
- Dependency management
- Static vs dynamic linking
- Shared libraries (.dll/.so)
- Order-only dependencies
- Symbol visibility
- ODR (One Definition Rule)
- Compiler optimization levels (
-O0,-O1,-O2,-O3,-Os) - Link-time optimization (LTO)
- Profile-guided optimization (PGO)
- When to optimize
- Measuring performance impact
- Debug vs Release builds
- GDB basics
- AddressSanitizer, MemorySanitizer, UndefinedBehaviorSanitizer
- Valgrind
- Debug symbols (
-g) - Logging and assertions
- vcpkg (Microsoft's package manager)
- Conan
- System package managers
- FetchContent
- Choosing dependencies
Key Questions Answered:
- How do I build a C++ project from scratch?
- What happens during compilation?
- How do I optimize my code?
- How do I find and fix bugs?
- How do I manage dependencies?
Before starting this module, you should have completed:
- ✅ 01_memory_control - Understanding of memory, pointers, RAII
- ✅ 02_zero_cost_abstraction - Classes, move semantics, smart pointers
- Basic C++ syntax familiarity
- Working development environment
-
Start with:
01_stl- The foundation of C++ programming- Learn containers → algorithms → iterators → lambdas
-
Then:
02_modern_features- Write modern C++ code- Auto, range-for, lambdas → tuples, optional, variants → advanced features
-
Finally:
03_compilation- Understand and control your build- CMake → linking → optimization → debugging → tooling
| Sub-Module | Time |
|---|---|
| 01_stl | 4-6 hours |
| 02_modern_features | 4-6 hours |
| 03_compilation | 2-3 hours |
| Total | 10-15 hours |
With practice: 3-4 weeks to become proficient.
Need to store data?
│
├─ Sequential access only?
│ └─ Array with fixed size?
│ ├─ Yes → std::array
│ └─ No → std::deque (if frequent front insertion)
│ └─ std::vector (default choice)
│
├─ Need key-value lookup?
│ └─ Sorted order required?
│ ├─ Yes → std::map / std::set
│ └─ No → std::unordered_map / std::unordered_set (faster)
│
├─ Need priority queue?
│ └─ std::priority_queue
│
└─ Need LIFO / FIFO?
├─ std::stack (LIFO)
└─ std::queue (FIFO)
| Container | Random Access | Insert | Delete | Search |
|---|---|---|---|---|
vector |
✓ O(1) | O(n)* | O(n)* | O(n) |
deque |
✓ O(1) | O(1) | O(1) | O(n) |
list |
✗ O(n) | ✓ O(1) | ✓ O(1) | O(n) |
map |
✓ O(log n) | O(log n) | O(log n) | O(log n) |
unordered_map |
✓ O(1)** | O(1) | O(1) | O(1) |
*Amortized for end, O(n) for middle **Average case, worst O(n)
cmake -G Ninja -B build
cmake --build build# STL containers
./build/bin/toolbox_stl_containers_*.exe
# STL algorithms
./build/bin/toolbox_stl_algorithms_*.exe
# Modern features
./build/bin/toolbox_modern_*.exe
# Compilation
./build/bin/toolbox_compilation_*.exe"The STL is not a collection of classes. It's a collection of algorithms that operate on iterators that traverse containers." - Alexander Stepanov
The magic of STL: Algorithms are decoupled from containers!
// Same algorithm works on ANY container
std::sort(v.begin(), v.end()); // vector
std::sort(l.begin(), l.end()); // list
std::sort(a.begin(), a.end()); // arrayC++11 Rule of Thumb:
- Use
autowhen type is obvious - Use
range-forfor simple iteration - Use lambdas for local functions
- Use
unique_ptrfor ownership - Use
make_shared/make_unique
C++17 Rule of Thumb:
- Use structured bindings
- Use
std::optionalfor nullable values - Use
std::filesystemfor paths - Use
ifwith initializer
C++20 Rule of Thumb:
- Use concepts for template constraints
- Use ranges for pipeline-style algorithms
- Use
std::formatinstead of iostream - Use
[[likely]]/[[unlikely]]attributes
C++23 Rule of Thumb:
- Use
std::printinstead ofstd::cout - Use Deducing This for member functions
- Use
std::flattenfor tuples - Use std::expected for error handling
- "The C++ Standard Library" by Nicolai Josuttis
- "Effective STL" by Scott Meyers
- "C++20: The Complete Guide" by Nicolai Josuttis
- "Professional C++" by Marc Gregoire
- C++ Reference - Complete STL reference
- C++ Core Guidelines - Best practices
- Compiler Explorer - See assembly output
- CppCon Talks - Conference videos
After completing this module, you should be able to:
- Choose the right container for any use case
- Use STL algorithms instead of writing loops
- Write custom iterators and predicates
- Use lambdas effectively
- Understand iterator categories
- Use
autoappropriately - Write range-for loops
- Create and use lambdas
- Use
std::optional,std::variant,std::any - Understand C++20 concepts and ranges
- Write a CMakeLists.txt from scratch
- Debug with sanitizers
- Profile and optimize code
- Manage dependencies with vcpkg
- Understand linking and symbols
After completing The Toolbox, continue to:
- Advanced Topics - Concurrency, networking, graphics
- Domain-Specific Learning - GUI, game dev, systems programming
- Real Projects - Build something substantial
"Don't reinvent the wheel. The standard library is battle-tested, optimized, and portable."
The toolbox module teaches you to:
- Leverage existing solutions instead of writing from scratch
- Write idiomatic C++ that other developers understand
- Build on proven foundations that work across platforms
- Stay productive by using high-level abstractions
Remember: The best code is code you don't have to write!
Module Status: 📝 Planned (Not yet implemented) Prerequisites:
- ✅
01_memory_controlComplete - ✅
02_zero_cost_abstractionComplete
Next Module: Advanced Topics (To be determined)
Last Updated: 2026-02-03 C++ Standard: C++23 Target Compilers: Clang 20.1.0, MSVC 19.4+, GCC 13+