Leanpub Header

Skip to main content

The C++ STL Handbook

Containers, Algorithms, Iterators, Ranges, and Beyond

The C++ STL Handbook
This book is 100% completeLast updated on 2026-08-21

Go beyond C++ syntax and learn to use the STL with confidence. Explore containers, algorithms, iterators, ranges and more through practical examples, performance insights and real-world patterns. Build a deeper understanding of how the STL works, when to use each tool and how to write cleaner, faster and more maintainable C++.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
203
Pages
About

About

About the Book

This book takes you from knowing basic C++ syntax to writing professional, production-quality code with the STL. You will learn every major container family, all standard algorithms organized conceptually, iterators and their categories, ranges in modern C++, allocators, parallel execution policies, and the design philosophy that ties everything together. Each chapter builds on the last, with complete compilable examples, complexity guarantees, performance analysis, debugging guidance, and real-world patterns. By the end, you will understand not only how to use each STL facility but when to use it, why it works the way it does, and how to compose STL components elegantly to solve practical problems at scale.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 420 engineers and researchers. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

Containers, Algorithms, Iterators, Ranges, and Beyond

Introduction: What Is the STL?

  1. The Original STL and Stepanov’s Vision
  2. Separation of Containers, Iterators, and Algorithms
  3. Generic Programming as a Design Philosophy
  4. What This Book Covers and How to Read It

Chapter 1: Templates and Genericity

  1. Function Templates: Syntax, Deduction, and Instantiation
  2. Class Templates and Specialization
  3. Template Constraints and SFINAE (Historical Context)
  4. Concepts as Modern Compile-Time Constraints
  5. How Templates Enable Zero-Cost Abstractions

Chapter 2: Iterators — The Bridge Between Containers and Algorithms

  1. What Is an Iterator and Why Does It Exist?
  2. Iterator Categories: Input, Output, Forward, Bidirectional, Random Access, Contiguous
  3. Iterator Concepts in Modern C++
  4. Dereferencing, Incrementing, Comparing: The Core Operations
  5. Building Custom Iterators for Your Types

Chapter 3: Sequence Containers — Vectors, Deques, Lists, and Arrays

  1. std::vector: Dynamic Arrays, Growth Strategy, Cache Locality, and Invalidation Rules
  2. std::deque: Double-Ended Queues and Their Trade-offs
  3. std::list and std::forward_list: Linked Lists in Modern C++
  4. std::array and std::span: Fixed-Size and View-Based Alternatives
  5. Choosing Your Sequence Container: A Decision Framework

Chapter 4: Associative Containers — Ordered Trees

  1. How Balanced Trees Power std::map and std::set
  2. Lookup, Insertion, Deletion: Complexity and Iterator Stability
  3. Multisets and Multimaps: Handling Duplicate Keys
  4. Key Comparison: Default Behavior and Custom Comparators
  5. Range Queries and Ordered Traversal Patterns

Chapter 5: Unordered Containers — Hash Tables

  1. Hash Tables: The Core Idea Behind Unordered Containers
  2. std::unordered_set and std::unordered_map: Interfaces and Guarantees
  3. Custom Hashers for User-Defined Types
  4. Load Factor, Rehashing, and Performance Tuning
  5. Ordered vs. Unordered: When Each Wins

Chapter 6: Container Adapters and Specialized Containers

  1. Stack and Queue: Restricting Interfaces for Safety
  2. Priority Queue: Heaps Behind a Simple Interface
  3. std::bitset: Efficient Bit-Level Operations
  4. Modern Specialized Containers: optional, variant, any, string_view
  5. Adapter Design: Why Limiting an Interface Is a Feature

Chapter 7: Allocators — Controlling Memory Management

  1. What Is an Allocator and Why Does It Matter?
  2. The Default Allocator and How Containers Use It
  3. Writing Custom Allocators: Requirements and Patterns
  4. Pool Allocators and Arena Allocation for Performance
  5. When (and When Not) to Customize Allocation

Chapter 8: Algorithms — Non-Modifying Operations

  1. Iteration Patterns: For_Each, Find, Count, and Their Variants
  2. Searching Algorithms: Binary Search, Lower Bound, Equal Range
  3. Numeric Algorithms: Accumulate, Inner Product, Reduce
  4. Relational Algorithms: Comparing Ranges Element-Wise
  5. Predicates, Lambdas, and Projections in Algorithm Calls

Chapter 9: Algorithms — Modifying Operations

  1. Copying and Moving: From std::copy to Transformative Operations
  2. Filling and Generating Ranges Programmatically
  3. The Erase-Remove Idiom and Modern Alternatives
  4. Sorting Algorithms: Sort, Stable_Sort, Partial_Sort, and Their Guarantees
  5. Merging, Shuffling, and Permuting Elements

Chapter 10: Function Objects, Lambdas, Predicates, and Comparators

  1. Function Objects: Operator Overloading for Callability
  2. Lambda Expressions: Syntax, Captures, and Mutability
  3. Predicates: Boolean Conditions That Drive Algorithms
  4. Comparators: Strict Weak Ordering and Custom Sort Keys
  5. Projections: Extracting Values Before Applying Operations

Chapter 11: Utility Types and Helper Facilities

  1. Pair and Tuple: Grouping Heterogeneous Values
  2. Type Traits: Compile-Time Introspection for Generic Code
  3. Reference Wrappers and Move Semantics Utilities
  4. Chrono Library: Time Points, Durations, and Clocks
  5. How Utilities Enable Advanced STL Patterns

Chapter 12: Ranges — The Modern C++ Revolution

  1. From Iterators to Ranges: Why This Evolution Matters
  2. Range Concepts: Borrowed Ranges, Sized Ranges, and Viewability
  3. Views and Adapters: Filter, Transform, Take, Drop, and More
  4. Pipelines: Composing Operations Readably and Lazily
  5. Ranges Algorithms: The Modern Way to Process Data

Chapter 13: Parallelism and Execution Policies

  1. Execution Policies: Sequential, Parallel, Vectorized, and Unsequenced
  2. Thread Safety Requirements for Parallel Algorithms
  3. When Parallelism Helps — And When It Hurts
  4. Practical Patterns for Safe and Effective Parallel STL

Chapter 14: Design, Performance, and Expert Patterns

  1. Internal Implementation Ideas: How STL Containers Are Built
  2. Cache Locality, Allocation Costs, and Real-World Performance
  3. Compile-Time Optimization: Inlining, Monomorphization, and NOOP Elimination
  4. Advanced Composition Patterns for Production Code
  5. Debugging STL Code: Tools, Diagnostics, and Common Pitfalls
  6. STL Common Anti-Patterns and Modern Alternatives
  7. Best Practices for Production-Quality STL Code

Conclusion: The STL as a Living System

  1. What Mastery of the STL Actually Means
  2. Design Principles That Transfer to Your Own Code
  3. The Future: Ranges Evolution, Coroutines Integration, and Beyond
  4. A Final Word on Writing C++ That Lasts

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub