Documentation

Modern C++ is a collection of deep, code-first documentation for the C++ language as it exists today — C++11 through C++23. Every page is built around complete, working programs. Samples marked with a Run in Compiler Explorer link open directly in Compiler Explorer with the right flags already set, so you can run and modify them in one click. Everything on this site compiles cleanly with -std=c++23 -Wall -Wextra.

Features are labeled with the standard that introduced them, like this: C++23. If a page covers a feature that changed across standards, each refinement is labeled where it appears.

Core language features

How to write today's C++ at the language level: type deduction, initialization, enumerations, iteration, conversions, namespaces, and the deduction machinery that removes boilerplate.

Numbers and strings

Working with data's two most common shapes: numeric types and their properties, text in all its encodings, randomness done right, user-defined literals, regular expressions, and the modern formatting stack.

Exploring functions

Everything callable: explicit control of the special member functions, lambdas from first principles through recursion, templates over any number of arguments, fold expressions, and the higher-order patterns — map, fold, composition, uniform invocation — that turn functions into building blocks.

Preprocessing and compilation

What happens before and during compilation, and how to steer it: conditional compilation, the preprocessor's token machinery, assertions the compiler evaluates, templates that filter themselves out of overload resolution, branches selected at compile time, and the metadata attributes that make the compiler catch your callers' mistakes.

Standard library containers, algorithms, and iterators

The standard library's working core: the containers that own your data, the algorithms that transform it, and the iterators that connect the two. This chapter is in progress — pages land as they are finished.

  • Using vector as a default container

    Why contiguous storage wins by default: every way to create one, size vs capacity, adding and removing elements, the invalidation rules, and lending the buffer to C APIs.

  • Using bitset for fixed-size sequences of bits

    Exactly N bits with named operations: building bitsets from integers and strings, testing and flipping bits, the bitwise operators, conversions out, and replacing hand-rolled flag masks.

  • Using vector<bool> for variable-size sequences of bits

    The packed vector specialization as a run-time-sized bitset: what the proxy reference changes, spelling bitset's verbs with algorithms, the sieve sized at run time, and when real bools serve better.

  • Using the bit manipulation utilities

    The C++20 <bit> header's integer utilities: counting and visiting set bits, the power-of-two helpers, rotations without undefined edges, endian and byteswap, and type punning with bit_cast.

  • Finding elements in a range

    The standard library's search algorithms: find and its predicate variants, locating subranges from either end, searchers for fast substring scans, the min and max element family, and the logarithmic lookups on sorted ranges.

  • Sorting a range

    The standard sorting algorithms: sort and its stability-preserving stable_sort, partial sorts in place or into a separate copy, nth_element for selection without a full sort, and the is_sorted checks that report whether and how far a range is ordered.

  • Initializing a range

    The algorithms that fill a range with values: fill and fill_n for a single value, generate and generate_n for values from a function, iota for consecutive sequences, and a real-life color gradient that puts them to work.

  • Using set operations on a range

    The algorithms that combine sorted ranges: set_union and merge for putting two ranges together, set_intersection for what they share, set_difference and set_symmetric_difference for what they do not, includes for subset tests, and a task type that reveals how each one chooses among equivalent elements.

  • Using iterators to insert new elements in a container

    The adapters that let an algorithm grow a container: back_inserter, front_inserter, and inserter, the output-iterator operations they redefine to make assignment mean insertion, the reversal front_inserter performs, and the position hint that associative containers are free to ignore.

  • Writing your own random-access iterator

    In progress.

In progress

Phases 1 through 4 cover core language features, working with numbers and strings, exploring functions, and preprocessing and compilation; phase 5 — the standard library's containers, algorithms, and iterators — is underway above. Future phases will go equally deep on ranges, general-purpose utilities, and threading and concurrency.

External references