Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Preface

This book teaches C++ as if it were always C++26, using only a small allow‑list of legacy constructs taught explicitly: raw pointers and new/delete for RAII, virtual functions for type erasure, C strings and errno for C interop, and SFINAE for reading existing code.

The book has four parts and a set of appendices. Part I covers the language. Part II covers the standard library. Part III covers generic and compile‑time programming. Part IV covers systems topics. The appendices hold reference material, including a feature table and a Core Guidelines index.

Who this book is for

You are an experienced programmer who already knows C, Rust, Lisp, and Prolog, and you have never written C++. The book assumes you understand functions, structs, loops, ownership, and metaprogramming at a high level. It never wastes a sentence describing a basic function. Instead, every paragraph highlights what is specific to C++, or how C++ differs from the languages you already master.

Each chapter assumes you can read code in at least one of these languages. It does not re‑teach loops or structs. It focuses on the C++ way to express an idea you already know. You will learn the vocabulary of modern C++, the ownership model, and the tools that verify the examples.

How the book reads

The book is a tour, not a reference. Each chapter introduces a cluster of related ideas, connects them to what came before, and ends with a single challenge under a “Try this” heading. There is no solutions appendix. The examples are real files, compiled and run by the toolchain that ships with the book, so what you read is exactly what the compiler accepted.

The tour is cumulative. Later chapters assume the vocabulary of earlier ones. The capstone in Part III ties the ideas together with a constexpr SQL interpreter. You can read the chapters in order, or jump to a topic and follow its cross‑references back.

The toolchain

The book is built with a Nix dev shell that pins LLVM 22.1.8, its libc++, and the Clang tools. nix develop gives you the whole environment. scripts/verify.sh runs the complete acceptance pipeline. The pipeline builds the book and verifies that every example is correct. It follows this order:

  1. scripts/verify.sh enters the Nix dev shell and runs scripts/verify-inner.sh. The inner script checks that clang++ is version 22 or newer, because the lifetime‑safety analysis requires it.
  2. CMake configures the build with cmake --preset dev. It probes the compiler for the lifetime‑safety flag and assembles the warning set.
  3. cmake --build build compiles every example with the warning set, -Werror, and clang‑tidy. A warning becomes a hard error, so a clean example stays clean.
  4. CTest runs each compiled example under the sanitizers. Each book_example test must match its EXPECT regular expression.
  5. mdbook build renders the book. It includes each example file directly from examples/, so the printed code is the compiled code.

A feature that is new in C++26 but not yet implemented by this compiler is taught prose‑first and marked with a “Not yet deployable” callout, so the book never presents code it cannot verify.

A note on style

The code follows the C++ Core Guidelines. Types and functions use snake_case, functions declare their return type before their name, and errors are reported through exceptions or std::expected, never through errno or out‑parameters. Wherever a rule comes from the Core Guidelines, it is cited inline, for example (CG F.15), and collected in Appendix C. The prose emphasizes clarity, brevity, and direct comparison to your existing language experience.