Skip to content
C++

Standard Library Reference

151 pages covering the C++ standard library — containers, algorithms, concurrency, memory, and modern utilities up to C++26.

Containers

19 pages

Sequence, associative, unordered, and flat containers. When to use each.

Container Adaptors

Wrapper classes that restrict and redefine the interface of sequence containers to model stacks, queues, and priority queues.

C++98
deque, list, queue, stack, priority_queue

"Sequential containers and adaptors: deque for double-ended operations, list for stable iterators, queue/stack/priority_queue adaptors. Choose based on insertion pattern and iterator requirements."

C++98
Iterator Invalidation

Rules governing when container operations cause previously-obtained iterators, pointers, and references to become undefined to dereference.

List

Doubly-linked list container optimized for efficient insertion and removal at any position

C++98
std::array

Fixed-size contiguous array wrapper with value semantics, bounds checking, and full STL compatibility.

C++11
std::deque

Double-ended queue supporting fast insertion and deletion at both ends with random access

C++98
std::flat_map

C++23 sorted associative container adaptor storing key-value pairs contiguously, giving map semantics with cache-friendly sequential layout.

C++23
std::flat_set and std::flat_map (C++23)

Sorted associative container adapters backed by contiguous storage — O(log n) binary search with cache-friendly memory layout, ideal for read-heavy workloads.

C++23
std::forward_list — Singly Linked List

C++ std::forward_list for singly-linked storage with O(1) front insertion, minimal memory per node, forward-only iteration, and when to use it over std::list.

C++11
std::hive

A C++26 sequence container providing O(1) insertion and erasure with stable iterators via a block-based, skipfield-backed memory layout.

C++26
std::map / std::unordered_map

std::map (sorted red-black tree, O(log n)) and std::unordered_map (hash table, O(1) avg): when to pick each, how to tune performance, and C++17/20/23 additions.

C++98
std::multimap and std::multiset

Ordered associative containers allowing duplicate keys — equal_range, node handles, erase semantics, and flat variants.

C++98
std::set and std::unordered_set

Ordered unique-element container backed by a red-black tree (set) and hash-table unique-element container (unordered_set) in C++.

C++98
std::span — Non-Owning Contiguous View

"C++20 std::span: a zero-overhead view over contiguous data. Fixed vs dynamic extent, subspans, byte reinterpretation, and API design patterns."

C++20
std::stack, std::queue, and std::priority_queue

C++ container adaptors — stack (LIFO), queue (FIFO), and priority_queue (heap-based) with underlying container selection, complexity, and practical patterns.

C++98
std::string

std::string — owning mutable character sequence with SSO, full modification API, searching, numeric conversions, and C++17/20/23 additions.

C++98
std::unordered_map

Hash map with O(1) average insert, lookup, and erase — the default associative container when key ordering is irrelevant.

C++11
std::vector

Dynamic contiguous array container. Default choice for sequential collections. O(1) random access and amortized O(1) append. Reallocates when capacity exhausted.

C++98
unordered_set and unordered_multiset

Hash-based sets with O(1) average lookup—custom hashing, rehashing, iterator invalidation, C++17/20 additions, and performance traps.

C++11

Algorithms

21 pages

Sorting, searching, transforming, set operations, numeric algorithms, parallel policies.

Binary Search

std::binary_search, lower_bound, upper_bound, equal_range and partition_point: logarithmic search over sorted ranges, with ranges variants, comparators and pitfalls.

C++98
Fold Operations

Reduce a range to a single value using std::accumulate, std::reduce, std::transform_reduce, and the C++23 ranges::fold family.

C++98
Heap Operations

Algorithms for creating, maintaining, querying, and sorting heap-ordered ranges in-place using random-access iterators.

C++98
Lexicographical Compare

std::lexicographical_compare and its C++20 siblings: dictionary-order comparison of two ranges, custom comparators, parallel overloads, and three-way results.

C++98
Min/Max Algorithms

Complete guide to std::min, std::max, std::minmax, clamp, and their range-element variants—signatures, version history, pitfalls, and idiomatic C++20 usage.

C++98
Modifying Sequence Algorithms

STL algorithms from <algorithm> that mutate a target range by copying, filling, generating, transforming, replacing, or rearranging elements.

Non-Modifying Sequence Algorithms

C++ non-modifying algorithms — for_each, count, count_if, any_of, all_of, none_of, find, find_if, mismatch, equal, and their C++20 ranges equivalents.

C++98
Numeric Algorithms — <numeric>

Complete reference for C++ numeric algorithms: accumulate, reduce, transform_reduce, prefix scans, gcd, lcm, midpoint, lerp, and parallel variants.

C++98
Parallel Algorithms (C++17)

C++17 execution policies for STL algorithms — par, par_unseq, reduce, transform_reduce, scan, thread safety, and platform requirements.

C++17
Partitioning Algorithms

Reorder, inspect, and copy elements based on a predicate with std::partition and its companion algorithms.

C++98
Permutation Algorithms

Generate and enumerate lexicographic permutations, check range equivalence, and randomly shuffle sequences using the C++ Standard Library.

C++98
Ranges & Views — Complete Reference

"C++20 ranges and views: range concepts, lazy view adaptors, composable pipelines, projections, and the pitfalls that bite experienced engineers."

C++20
Scan Operations

Prefix-sum algorithms in <numeric>: partial_sum (C++98) and the parallel-capable inclusive_scan, exclusive_scan, and transform variants added in C++17.

C++98
Searching Algorithms

C++ searching algorithms — std::find, binary_search, lower_bound, upper_bound, equal_range, search, and C++20 ranges equivalents with projections.

C++98
Set and Heap Algorithms

Set algorithms operating on sorted ranges and heap operations — multiset semantics, complexity guarantees, and C++20 ranges versions.

C++98
Sorting Algorithms

"C++ sorting: std::sort, std::stable_sort, std::partial_sort, std::nth_element, ranges variants, custom comparators, and strict weak ordering."

C++98
std::merge / std::inplace_merge

Merge two sorted ranges into a single sorted output range. Both std::merge and std::inplace_merge are stable and have been available since C++98.

C++98
std::sample

Select n elements uniformly at random without replacement from a population range, preserving their relative order.

C++17
STL Algorithms Overview

Complete guide to <algorithm> and std::ranges algorithms — sorting, searching, transforming, partitioning, and parallel execution.

C++98
Transforming and Mutating Algorithms

Deep reference for std::transform, for_each, copy, fill, generate, remove, rotate, and C++20 ranges equivalents with pitfalls and best practices.

C++98
Uninitialized Memory Algorithms

Low-level algorithms for constructing, copying, moving, and destroying objects in raw allocated storage, decoupling allocation from object lifetime management.

C++98

Concurrency

17 pages

Threads, mutexes, atomics, futures, jthread, semaphore, latch, barrier.

Condition Variables

std::condition_variable — atomic wait/notify, spurious wakeup handling, timed waits, condition_variable_any, and C++20 stop_token integration.

C++11
Lock-Free Programming

C++ lock-free programming — compare_exchange, memory orders, Treiber stack, ABA problem, safe reclamation, and when to prefer mutexes.

C++11
Read-Copy Update (RCU)

Lock-free reader synchronization for read-heavy workloads — readers never block; writers retire old data after a guaranteed grace period.

C++26
Semaphore, Latch, and Barrier (C++20)

C++20 counting_semaphore, binary_semaphore, latch, and barrier — efficient thread synchronization primitives with defined happens-before semantics.

C++20
std::async, future, promise, packaged_task

"C++11 async primitives: std::async for task-based concurrency, future/promise as a one-shot cross-thread value channel, packaged_task for callable wrapping."

C++11
std::atomic

std::atomic<T> provides lock-free atomic operations with configurable memory ordering — covers memory orders, CAS loops, atomic_flag, atomic_ref, wait/notify, and fences.

C++11
std::atomic_ref

Apply atomic operations to existing non-atomic objects with std::atomic_ref (C++20): syntax, alignment rules, specializations, and pitfalls.

C++20
std::call_once and std::once_flag

Thread-safe one-time initialization in C++11 with std::call_once and std::once_flag, including exception semantics, lazy init patterns, and comparison with function-local statics.

C++11
std::execution — Senders & Receivers (C++26)

P2300 Senders/Receivers: structured, composable async that decouples work from execution context — portable parallelism across thread pools, GPU queues, and event loops without callbacks.

C++26
std::jthread and Cooperative Cancellation (C++20)

"C++20 std::jthread: auto-joining thread with cooperative cancellation via stop_token, stop_source, and stop_callback."

C++20
std::memory_order

Controls how memory accesses around atomic operations are ordered across threads; the backbone of C++'s lock-free concurrency model.

C++11
std::mutex, lock_guard, unique_lock, scoped_lock, condition_variable

C++ mutual exclusion primitives — mutex variants, RAII lock guards, condition variables, and correct patterns for thread-safe code.

C++11
std::packaged_task

A move-only callable wrapper that stores its result or exception in a shared state accessible via std::future.

C++11
std::promise

Write-end of a one-shot, thread-safe channel; pairs with std::future to pass a value or exception across threads.

C++11
std::shared_mutex

C++17 reader-writer mutex allowing multiple concurrent shared (read) locks alongside a single exclusive (write) lock, eliminating false serialization of reads.

C++17
std::thread, mutex, atomic, condition_variable

C++11 portable threading model — thread creation, mutual exclusion, lock-free atomics, and condition-variable signaling for safe concurrent programs.

C++11
thread_local Storage Duration

C++ thread_local — per-thread variables, initialization semantics, destruction order, async pitfalls, and performance characteristics.

C++11

Memory

12 pages

Smart pointers, allocators, placement new, memory resources (PMR).

construct_at / destroy_at

Low-level object lifetime utilities for constructing and destroying objects in raw memory without invoking operator new or delete.

C++17
Custom Allocators and PMR

C++ custom allocators and C++17 polymorphic memory resources: arena, pool, PMR containers, allocator propagation, and zero-heap hot paths.

C++17
Memory Management

C++ memory management — RAII, smart pointers, arenas, PMR allocators, object pools, placement new, and avoiding heap pitfalls.

C++11
observer_ptr

A non-owning pointer wrapper from the C++ Library Fundamentals TS that makes non-ownership explicit at the type level.

Placement new and Manual Object Lifetime

Construct objects in pre-allocated memory using placement new, std::construct_at, std::destroy_at, and std::launder for allocators, pools, and variant storage.

C++98
Smart Pointers

unique_ptr, shared_ptr, and weak_ptr — ownership semantics, control block internals, custom deleters, cycle breaking, and enable_shared_from_this.

C++11
std::out_ptr and std::inout_ptr

C++23 RAII proxy adapters that let smart pointers be passed directly to C-style T** output-parameter APIs without unsafe casts or manual resets.

C++23
std::pmr::memory_resource

Abstract base class for C++17 polymorphic memory resources; decouples allocation strategy from container type via runtime polymorphism.

C++17
std::shared_ptr

A reference-counted smart pointer that enables shared ownership of a dynamically allocated object, deleting it when the last owner is destroyed.

C++11
std::unique_ptr

Exclusive-ownership smart pointer that automatically frees its managed object when it goes out of scope, with zero overhead over a raw pointer.

C++11
std::weak_ptr

A non-owning smart pointer that observes a shared_ptr-managed object without extending its lifetime, enabling cycle-breaking and safe expiry detection.

C++11
weak_ptr Patterns

C++ weak_ptr usage patterns — breaking cycles, observers, caches, enable_shared_from_this, and thread-safe access via lock().

C++11

Strings

8 pages

std::string, std::string_view, std::format, string algorithms, conversions.

Utilities

74 pages

optional, variant, expected, any, function, chrono, filesystem, span, bitset, and more.

<bit>

C++20 header providing portable bit manipulation — rotation, counting, power-of-two math, endianness detection, and safe type-punning via bit_cast.

C++20
<cfenv>

C++11 header for IEEE 754 floating-point environment control — exception flags, rounding modes, and environment save/restore.

C++11
<cmath>

Standard C++ header providing mathematical functions for floating-point arithmetic, rounding, classification, and error handling.

C++98
<compare>

Three-way comparison ordering categories, the &lt;=> spaceship operator, and named comparison helpers introduced in C++20.

C++20
<csignal>

C-style signal handling in C++ — signal(), raise(), std::sig_atomic_t, and the strict rules for writing portable, async-signal-safe handlers.

C++98
<cstdint>

Fixed-width integer type aliases and limit macros for portable, size-explicit integer programming in C++.

C++11
<cstdlib>

C++ wrapper for C's stdlib.h, providing process control, raw memory allocation, numeric conversions, integer arithmetic, and pseudo-random numbers.

C++98
<cstring>

C++ header providing null-terminated string manipulation and raw memory operation functions inherited from C's <string.h>.

C++98
<functional> — Function Objects and Callable Utilities

The <functional> header provides function objects, std::function, std::bind, std::invoke, and callable wrappers for composing and passing behavior as first-class values.

C++98
<iomanip>

Parameterized stream manipulators for field width, fill character, numeric base, floating-point precision, monetary formatting, and date/time I/O.

C++98
<spanstream>

C++23 header providing stream I/O over std::span<char> buffers — fixed-capacity, zero-allocation alternatives to <sstream>.

C++23
<stdfloat>

C++23 header providing optional fixed-width extended floating-point types including IEEE 754 half, single, double, quad, and bfloat16 formats.

C++23
<system_error>

Portable, extensible error-code infrastructure for reporting OS and library errors as values rather than exceptions, introduced in C++11.

C++11
<typeinfo>

The <typeinfo> header provides std::type_info and bad_typeid — C++'s built-in runtime type identification primitives used with the typeid operator.

C++98
<utility>

The <utility> header provides foundational C++ building blocks — move, forward, swap, exchange, pair, declval, and safe integer comparisons.

C++98
<version>

C++20 header that centralises all standard library feature-test macros for portable compile-time capability detection.

C++20
Concepts Library

The C++20 <concepts> header provides standard named constraints — std::integral, std::regular, std::invocable — replacing SFINAE boilerplate with readable, composable template interfaces.

C++20
Cstdio

<cstdio> exposes C stdio (printf, fopen, snprintf, fread) in namespace std: formatted and binary file I/O, its pitfalls, and modern C++ alternatives.

C++98
Debugging Utilities

C++26 <debugging> header — std::breakpoint(), std::is_debugger_present(), and std::breakpoint_if_debugging() for programmatic debugger integration.

C++26
Exception Classes

The std::exception hierarchy, when to throw each standard type, how to write custom exceptions, and how to nest and transport exceptions across threads.

C++98
Execution Policies

Tag types and global constants that control whether STL algorithms run sequentially, in parallel, or with SIMD vectorization — introduced in C++17.

C++17
fstream

File stream classes for reading, writing, and random-access I/O on files; the <fstream> header provides ifstream, ofstream, and fstream.

C++98
iostreams — Input/Output Streams

"C++ iostream system: standard streams, file and string streams, stream state, manipulators, custom operators, rdbuf redirection, and performance tuning."

C++98
Iterator

The <iterator> header provides iterator categories, traits, adaptors, stream iterators, and free functions that bridge containers and algorithms.

C++98
Numeric Algorithms

"C++ numeric algorithms: accumulate, reduce, transform_reduce, prefix scans, inner_product, iota, gcd, lcm, midpoint, and lerp with parallel execution notes."

C++98
Random Number Generation

C++ <random> engines, distributions, seeding strategies, thread safety, and common pitfalls — from mt19937 to discrete_distribution.

C++11
Ranges Library

The C++20 ranges library provides composable, lazy sequences with concept-constrained algorithms and view adaptors via the pipe operator.

C++20
Reference Wrapper

std::reference_wrapper, std::ref and std::cref: copyable, assignable reference semantics for containers, bind, threads and generic callables.

C++11
sstream

Header providing std::istringstream, std::ostringstream, and std::stringstream for in-memory formatted I/O on std::string buffers.

C++98
std::any

Type-safe, type-erased container for a single value of any copy-constructible type, with runtime type queries and checked casts.

C++17
std::atomic

Thread-safe atomic operations without mutexes — memory orders, CAS loops, atomic_flag, atomic_ref (C++20), wait/notify (C++20), and lock-free patterns.

C++11
std::bind

std::bind, bind_front and bind_back: partial application, argument reordering and placeholders, with version history and when lambdas are the better choice.

C++11
std::bitset

Fixed-size bit manipulation with set/reset/flip/test, bitwise operators, and integer/string conversions — stack-allocated, no heap, no UB from shift overflow.

C++98
std::chrono

Type-safe time and duration library — durations, clocks, time points, and C++20 calendar and timezone types.

C++11
std::chrono — Advanced Usage

Advanced C++ chrono covering C++20 calendar types, time zones, zoned_time, date arithmetic, DST edge cases, formatting, and clock selection.

C++20
std::complex

Class template for complex number arithmetic with real and imaginary parts, arithmetic operators, math functions, and C++14 literals.

C++98
std::expected

C++23 vocabulary type holding either a success value T or an error value E, making failure modes explicit in the return type without exceptions.

C++23
std::filesystem

Cross-platform filesystem operations in C++17 — path manipulation, directory traversal, file status queries, and file I/O utilities.

C++17
std::flat_map and std::flat_set (C++23)

C++23 sorted contiguous-memory container adapters with O(log n) binary search and cache-friendly layout — no pointer chasing through tree nodes.

C++23
std::format

Type-safe, compile-time-checked text formatting introduced in C++20, replacing printf and stream-based output with Python-style format strings.

C++20
std::from_chars / std::to_chars

C++17 charconv — locale-independent, non-allocating, non-throwing conversion between numbers and character buffers.

C++17
std::function

A general-purpose polymorphic function wrapper that type-erases any callable matching a given signature, at the cost of runtime overhead.

C++11
std::hash and Custom Hash Functions

std::hash specialization, hash_combine design, transparent heterogeneous lookup (C++20), and custom hash requirements for unordered containers.

C++11
std::initializer_list

A lightweight, read-only view over a compiler-generated const array that enables brace-initialization syntax for functions and constructors.

C++11
std::inplace_vector (C++26)

Fixed-capacity vector with inline storage — dynamic size 0..N, no heap allocation, constexpr-compatible, and full std::vector-compatible API.

C++26
std::invoke

Uniformly call any callable (function, member pointer, functor, lambda) with std::invoke (C++17), std::invoke_r (C++23), and std::is_invocable traits.

C++17
std::linalg

C++26 BLAS-level 1/2/3 free functions operating on std::mdspan views for portable dense linear algebra without external library dependencies.

C++26
std::mdspan

Multi-dimensional non-owning view over contiguous data with pluggable layout and accessor policies. C++23 replacement for raw pointer and stride arithmetic.

C++23
std::numbers — Mathematical Constants

C++20 compile-time mathematical constants (π, e, φ, √2, and more) in <numbers>, available as double aliases and as precision-preserving variable templates.

C++20
std::numeric_limits

Class template providing compile-time type properties — range, precision, and representation flags — for all arithmetic types, replacing C-style macros.

C++98
std::optional

A value-or-nothing wrapper that eliminates sentinel values and nullable pointer workarounds in C++17.

C++17
std::optional Monadic Operations (C++23)

C++23 and_then, transform, and or_else on std::optional enable composable error-propagation pipelines without nested nullopt checks.

C++23
std::osyncstream

C++20 synchronized output stream that atomically transfers buffered content to a wrapped ostream, eliminating interleaved output in multithreaded programs.

C++20
std::pair and std::tuple

std::pair and std::tuple store multiple values. Structured bindings, std::tie, std::apply, and composition patterns for heterogeneous data.

C++11
std::ratio

Compile-time rational number arithmetic via template parameters — the unit system underlying std::chrono::duration.

C++11
std::regex

C++ regular expressions — regex_match, regex_search, regex_replace, capture groups, iterators, and when to reach for a faster library.

C++11
std::scoped_allocator_adaptor

C++11 allocator adaptor that propagates one or more allocators through every nesting level of a container hierarchy via std::uses_allocator.

C++11
std::simd — Portable SIMD (C++26)

std::simd<T, Abi>: type-safe portable SIMD in C++26 (P1928) — write vectorized code once, compile to SSE/AVX/NEON/SVE automatically without intrinsics or platform ifdefs.

C++26
std::source_location (C++20)

Capture file, line, column, and function name at the call site without macros — the C++20 replacement for __FILE__ and __LINE__.

C++20
std::span

Non-owning view over a contiguous sequence of objects. C++20's type-safe replacement for (pointer, length) pairs, working with arrays, vectors, std::array, and raw buffers.

C++20
std::stacktrace (C++23)

Capture and inspect runtime call stacks with std::stacktrace — frame iteration, exception integration, allocator control, and compiler setup.

C++23
std::stop_token / stop_source (C++20)

"C++20 cooperative cancellation primitives: stop_token, stop_source, stop_callback, and jthread integration for safe thread shutdown."

C++20
std::streambuf

Abstract base class for C++ stream buffers, mediating raw character I/O between higher-level streams and the underlying data device.

C++98
std::string_view

"Non-owning, read-only string reference (C++17): zero-copy substrings, universal parameter type, constexpr usage, and lifetime hazards."

C++17
std::tuple and std::pair

Fixed-size heterogeneous collections with value semantics — pair for two values, tuple for N values of any types, with structured bindings support.

C++11
std::type_index

A copyable, hashable wrapper around std::type_info enabling runtime type information to be used as keys in associative containers.

C++11
std::valarray

Numeric array with element-wise arithmetic, built-in math functions, and slice-based sub-array access for high-performance numerical computing.

C++98
std::variant

Type-safe tagged union holding exactly one of a fixed set of alternative types, introduced in C++17 with no heap allocation.

C++17
String Algorithms

C++ string operations — searching, splitting, trimming, case conversion, replace-all, and fast number parsing with from_chars and string_view.

C++98
String Conversions and std::locale

Fast, locale-independent parsing with from_chars/to_chars (C++17), convenient stoi/stod (C++11), and locale-aware formatting via std::locale and its facets.

C++11
Swap and Exchange

std::swap, std::exchange, and std::iter_swap: semantics, noexcept rules, the ADL swap idiom, and how to implement move operations and copy-and-swap correctly.

C++11
Text Encoding

C++ character types, encoding-aware string types, and conversion facilities for UTF-8, UTF-16, UTF-32, and locale-dependent encodings.

C++11
Time Ctime

C-style date and time facilities in <ctime>: time_t, tm, clock, localtime, gmtime, strftime, and safe interop with std::chrono.

C++98
Type Traits

"Compile-time type inspection and transformation via <type_traits>: primary categories, property queries, type modifications, and custom trait authoring."

C++11