Containers, Algorithms, Iterators, Ranges and Beyond
Introduction: What Is the STL?
- The Original STL and Stepanov’s Vision
- Separation of Containers, Iterators and Algorithms
- Generic Programming as a Design Philosophy
- What This Book Covers and How to Read It
Chapter 1: Templates and Genericity
- Function Templates: Syntax, Deduction and Instantiation
- Class Templates and Specialization
- Template Constraints and SFINAE (Historical Context)
- Concepts as Modern Compile-Time Constraints
- How Templates Enable Zero-Cost Abstractions
Chapter 2: Iterators - The Bridge Between Containers and Algorithms
- What Is an Iterator and Why Does It Exist?
- Iterator Categories: Input, Output, Forward, Bidirectional, Random Access, Contiguous
- Iterator Concepts in Modern C++
- Dereferencing, Incrementing, Comparing: The Core Operations
- Building Custom Iterators for Your Types
Chapter 3: Sequence Containers - Vectors, Deques, Lists and Arrays
- std::vector: Dynamic Arrays, Growth Strategy, Cache Locality and Invalidation Rules
- std::deque: Double-Ended Queues and Their Trade-offs
- std::list and std::forward_list: Linked Lists in Modern C++
- std::array and std::span: Fixed-Size and View-Based Alternatives
- Choosing Your Sequence Container: A Decision Framework
Chapter 4: Associative Containers - Ordered Trees
- How Balanced Trees Power std::map and std::set
- Lookup, Insertion, Deletion: Complexity and Iterator Stability
- Multisets and Multimaps: Handling Duplicate Keys
- Key Comparison: Default Behavior and Custom Comparators
- Range Queries and Ordered Traversal Patterns
Chapter 5: Unordered Containers - Hash Tables
- Hash Tables: The Core Idea Behind Unordered Containers
- std::unordered_set and std::unordered_map: Interfaces and Guarantees
- Custom Hashers for User-Defined Types
- Load Factor, Rehashing and Performance Tuning
- Ordered vs. Unordered: When Each Wins
Chapter 6: Container Adapters and Specialized Containers
- Stack and Queue: Restricting Interfaces for Safety
- Priority Queue: Heaps Behind a Simple Interface
- std::bitset: Efficient Bit-Level Operations
- Modern Specialized Containers: optional, variant, any, string_view
- Adapter Design: Why Limiting an Interface Is a Feature
Chapter 7: Allocators - Controlling Memory Management
- What Is an Allocator and Why Does It Matter?
- The Default Allocator and How Containers Use It
- Writing Custom Allocators: Requirements and Patterns
- Pool Allocators and Arena Allocation for Performance
- When (and When Not) to Customize Allocation
Chapter 8: Algorithms - Non-Modifying Operations
- Iteration Patterns: For_Each, Find, Count and Their Variants
- Searching Algorithms: Binary Search, Lower Bound, Equal Range
- Numeric Algorithms: Accumulate, Inner Product, Reduce
- Relational Algorithms: Comparing Ranges Element-Wise
- Predicates, Lambdas and Projections in Algorithm Calls
Chapter 9: Algorithms - Modifying Operations
- Copying and Moving: From std::copy to Transformative Operations
- Filling and Generating Ranges Programmatically
- The Erase-Remove Idiom and Modern Alternatives
- Sorting Algorithms: Sort, Stable_Sort, Partial_Sort and Their Guarantees
- Merging, Shuffling and Permuting Elements
Chapter 10: Function Objects, Lambdas, Predicates and Comparators
- Function Objects: Operator Overloading for Callability
- Lambda Expressions: Syntax, Captures and Mutability
- Predicates: Boolean Conditions That Drive Algorithms
- Comparators: Strict Weak Ordering and Custom Sort Keys
- Projections: Extracting Values Before Applying Operations
Chapter 11: Utility Types and Helper Facilities
- Pair and Tuple: Grouping Heterogeneous Values
- Type Traits: Compile-Time Introspection for Generic Code
- Reference Wrappers and Move Semantics Utilities
- Chrono Library: Time Points, Durations and Clocks
- How Utilities Enable Advanced STL Patterns
Chapter 12: Ranges - The Modern C++ Revolution
- From Iterators to Ranges: Why This Evolution Matters
- Range Concepts: Borrowed Ranges, Sized Ranges and Viewability
- Views and Adapters: Filter, Transform, Take, Drop and More
- Pipelines: Composing Operations Readably and Lazily
- Ranges Algorithms: The Modern Way to Process Data
Chapter 13: Parallelism and Execution Policies
- Execution Policies: Sequential, Parallel, Vectorized and Unsequenced
- Thread Safety Requirements for Parallel Algorithms
- When Parallelism Helps - And When It Hurts
- Practical Patterns for Safe and Effective Parallel STL
Chapter 14: Design, Performance and Expert Patterns
- Internal Implementation Ideas: How STL Containers Are Built
- Cache Locality, Allocation Costs and Real-World Performance
- Compile-Time Optimization: Inlining, Monomorphization and NOOP Elimination
- Advanced Composition Patterns for Production Code
- Debugging STL Code: Tools, Diagnostics and Common Pitfalls
- STL Common Anti-Patterns and Modern Alternatives
- Best Practices for Production-Quality STL Code
Conclusion: The STL as a Living System
- What Mastery of the STL Actually Means
- Design Principles That Transfer to Your Own Code
- The Future: Ranges Evolution, Coroutines Integration and Beyond
- A Final Word on Writing C++ That Lasts