Skip to content

C++ Beyond the Basics

Glossary

147 terms from C++ Beyond the Basics, in plain words, each with the chapter that teaches it.

#

= default and = delete
`= default` asks for the compiler's version of a special member, and `= delete` forbids it. Deleting both copy operations makes a move-only type.

A

Abbreviated function template
A function template written with `auto` (or `Concept auto`) parameters instead of a `template` line, such as `triple(std::integral auto n)`. The compiler makes a version for each type you call it with.
Abstract class
A class with at least one pure virtual function, so you can't create objects of it. Kettle & Crane's `Discount` is abstract because it has no pricing rule of its own.
AddressSanitizer (ASan)
A compiler-built checker, turned on with `-fsanitize=address`, that reports bad memory use such as reading past the end of a vector. It catches bugs that may otherwise appear to work.
Algorithm
A ready-made function from `<algorithm>` (or `<numeric>`) that works on a range of elements, such as `std::sort` or `std::find_if`. Using one replaces a hand-written loop.
and_then
A `std::expected` member that runs a function on the value, where that function itself returns an `expected`. Errors pass straight through without running it.
assert
A macro from `<cassert>` that stops the program if its condition is false, used as a bug check. It is disabled when `NDEBUG` is defined, as in CMake's Release build type.
Assertion
A check inside a test, such as `EXPECT_EQ(a, b)`. An `EXPECT_` failure is reported and the test goes on, while an `ASSERT_` failure stops the test at once.
Atomic
A type such as `std::atomic<int>` whose operations (`++`, `+=`, `.load()`) are single steps no other thread can split. It suits shared counters and flags.
Attribute
A note to the compiler written in double square brackets. `[[nodiscard]]` makes the compiler warn if a caller ignores the function's return value.

B

Base class
The class that another class inherits from. `Discount` is the base class for `PercentOff` and `BuyOneGetOne`.
Baseline
A long id (a git commit) in `vcpkg-configuration.json` that names one vcpkg version. It pins the version of every port so the project builds the same later.
Binary cache
vcpkg's store of already-built packages in your home folder. Later builds, even in other projects, reuse them in seconds.
BlockingQueue
The project's thread-safe queue class template: `pop()` sleeps until an item arrives, and `close()` wakes every waiter so `pop()` returns `std::nullopt` once the queue is empty.
By value
Passing or storing a copy of an object (or one moved in) rather than a reference. Passing a big vector by value to a function can be slow unless it's a sink parameter.

C

Capture
How a lambda takes variables from around it, listed in `[]`: by copy (`[limit]`), by reference (`[&total]`) or `[this]` for an object's members. A reference capture must not outlive its variable.
Class template
A class with type parameters, such as `template <typename T> class Queue`. The compiler writes a separate class for each type used, like `Queue<std::string>`.
Class template argument deduction
The compiler working out a class template's type arguments from the constructor arguments, so `std::vector v{1, 2};` is a `std::vector<int>`.
Closure
The small callable object the compiler builds from a lambda, holding any captured variables.
CMake
A build tool whose `CMakeLists.txt` file describes your program's targets, source files and libraries. It then drives the compiler for you.
cmake --preset and cmake --build
A pair of CMake commands: `cmake --preset debug` configures a project using the settings stored in a named preset, and `cmake --build build/debug` compiles the project in that build folder.
Comparator
A function that gets two elements and returns `true` if the first should come before the second. `std::sort` takes one as an optional third argument.
Compiler flags
Options given to the compiler: `-Wall -Wextra` enable warnings, `-pthread` links thread support on Linux, and `-g` adds line numbers for debugging.
Composition
Building a class from members for a "has a" relationship, such as an order having a customer, instead of inheriting.
Concept
A named rule a template's type must follow, such as `std::integral` or your own `Priced`. It is checked at the call, so errors are short.
Concurrency
Doing several things at once, for example several threads working on orders while another reads them in.
Condition variable
A `std::condition_variable` lets a thread sleep until another thread says something changed. The waiter calls `wait(lock, predicate)` and the other thread calls `notify_one()` or `notify_all()`.
Constraint
A rule on a template parameter, written with a concept in the template line, a `requires` clause or `Concept auto`. A type that breaks it is rejected at the call.
Copy assignment
`operator=` taking `const T&`, which copies one object's contents into an existing object. `copy = lines;` runs it.
Copy constructor
A constructor `T(const T&)` that builds a new object as a copy of an existing one, such as copying a vector of 10,000 order lines.
Copy elision
The compiler building a returned object directly in its destination, so no copy or move happens. This is why returning by value is cheap and `return std::move(t);` is discouraged.
Core
One of a processor's units, each able to run a thread at the same moment.
Critical section
Code that runs while a thread holds a mutex. Keep it short so other threads don't wait long.
ctest
CMake's test runner. `ctest --test-dir build/debug` runs all registered tests and reports which passed.

D

Data race
Two threads using the same data at once with at least one writing. It is undefined behavior and can silently lose updates, like Kettle & Crane's lost cup counts.
Deadlock
Threads each holding one mutex and waiting forever for another that a different thread holds. Locking in one order, or using `std::scoped_lock`, avoids it.
Debug build
Code built without optimization (`-O0 -g`), which keeps it easy to debug but slower.
Dependency
A library your project needs in order to build or run, such as nlohmann-json.
Derived class
A class that inherits from a base class, gaining its members and adding its own, as `PercentOff` does from `Discount`.
Digit separator
A `'` inside a number literal such as `1'000'000` that the compiler ignores. It just makes long numbers easier to read.
Dynamic dispatch
Choosing which `virtual` function to run at run time from the object's real type, through a base reference or pointer.

E

Emplace
`emplace_back` builds a new element directly inside a container from constructor arguments, avoiding a temporary and a copy.
enable_testing
CMake commands for tests: `enable_testing()` turns on the test runner, and `gtest_discover_tests` registers each GoogleTest test with it.
Environment variable
A named setting the shell passes to every program it starts. `VCPKG_ROOT` tells CMake where vcpkg is, and `PATH` lists the folders where the shell looks for programs, so adding vcpkg's folder lets you type `vcpkg`.

F

Factory function
A function that creates an object and hands it back, often as a `std::unique_ptr`, like `make_mug()`.
final
A keyword after a class name (`class PercentOff final`) that forbids deriving from that class.
find_package
CMake commands that locate an installed library (`find_package`) and connect it to your target (`target_link_libraries`), making its headers visible and linking its code.
Function template
A function with type parameters, starting `template <typename T>`. The compiler makes one version per type it is called with.

G

Generic lambda
A lambda with `auto` parameters, so it works for any type, such as one that prints both `325` and `"Hearth"`.
GoogleTest
The most used C++ test framework, providing `TEST`, `EXPECT_EQ` and a ready-made `main` in `GTest::gtest_main`.

H

Hash table
A container that turns a key into a number (its hash) to find the slot, so lookups usually check one slot. `std::unordered_map` is one, and its keys come out unsorted.
Heap
A big pool of memory you ask for and must give back, holding objects that outlive a function or whose number is known only at run time.
Hot spot
The code where a program spends most of its time. A profiler lists it at the top, and it's what to speed up first.

I

Include guard (#pragma once)
`#pragma once` at the top of a header stops it from being included twice in the same file.
Inheritance
Building one class on another with `class B : public A`, so the derived class gets the base's members.
Init capture
A lambda capture that creates a new variable inside the closure, such as `[n = 100]` or `[lines = std::move(lines)]`.
Instantiation
The compiler writing out a template's code for one set of type arguments. It is why `biggest<int>` is as fast as a hand-written `int` version.
Interface
A base class made only of pure virtual functions, listing what every derived type can do.
Iterator
An object pointing to an element in a container. Algorithms take an iterator range from `begin()` to `end()`, and `find_if` returns `end()` if nothing matches.

J

JSON
A text format of keys and values, such as `{"LAT": 475}`, widely used for settings and for data exchanged by web APIs. In C++ it can be read with a library such as nlohmann-json.
jthread
`std::jthread` is a thread that joins itself when destroyed, so you can't forget to call `.join()`.

L

Lambda
An unnamed function written inside an expression, such as `[](int c) { return c > 400; }`. You can store it in `auto`, pass it to algorithms or keep it in a `std::function`.
Lazy
Doing no work until it is needed. A view does nothing when made, and each element is filtered or converted only when the loop asks for it.
Library
Code written by others for you to use, such as a JSON reader.
Library target
A CMake `add_library` target of compiled code with no `main`, which both the program and the test program link to. It avoids compiling `order.cpp` twice.
Lock guard
`std::lock_guard` locks a mutex when created and unlocks it when destroyed, so an exception can't leave it locked.
lvalue
An expression with a name that lasts, such as `lines`; you can take its address with `&`.

M

Manifest mode
vcpkg reading a project's dependencies from its own `vcpkg.json` file. Each project lists the ports it needs.
Move assignment
`operator=` taking `T&&`, which takes another object's contents into an existing one. It returns `*this` and should be `noexcept`.
Move constructor
A constructor `T(T&&)` that builds a new object by taking another's contents instead of copying them. The source is left moved-from.
Move-only
A type that can be moved but not copied, made by deleting the copy operations. `std::unique_ptr` is one.
Moved-from
The state of an object whose contents were taken by a move: valid, but with an unspecified value. Only assign it a new value or let it be destroyed.
mutable (lambda)
A keyword after a lambda's parameters that lets it change its captured copies, which are `const` by default: `[n = 100]() mutable { return ++n; }`.
Mutex
A lock that only one thread at a time can hold. It protects bigger shared data such as a vector of tickets.

N

Ninja
A fast build program that runs the compiler commands CMake generates for a project. It is chosen as the CMake generator, for example in a preset.
nlohmann-json
A C++ library, installed as a vcpkg port, that parses JSON text into a `nlohmann::json` value you index with `j["key"]`.
noexcept
A promise that a function never throws. `std::vector` moves elements while growing only if the move constructor is `noexcept`; otherwise it copies.

O

Object slicing
Copying a derived object into a base object by value, which keeps only the base part. Pass `const Discount&` or use pointers to avoid it.
Optimizer
The part of the compiler that rewrites your code to run faster. `-O0` turns it off and `-O2` turns most of it on.
Override
A keyword saying a function replaces a base class's virtual function. If the signatures differ, you get a compile error.
Ownership
Being responsible for deleting an object. Smart pointers make ownership explicit so heap objects aren't leaked.

P

Package manager
A tool that downloads, builds and records the libraries a project depends on, such as vcpkg.
perf
A Linux profiling tool. `perf stat` prints overall counts, `perf record` samples a run, and `perf report --stdio` lists functions, busiest first.
Pipe
The `|` operator that chains views left to right, such as `cents | std::views::filter(f) | std::views::take(3)`.
Polymorphism
One piece of code serving many types, chosen at run time. A function taking `const Discount&` works for any kind of discount.
Port
vcpkg's recipe for building one library, such as `nlohmann-json` or `gtest`.
Predicate
A function returning `bool`. `condition_variable::wait` takes one and re-checks it after each wake-up, which makes spurious wake-ups harmless.
Preset
A named set of CMake settings stored in `CMakePresets.json`, such as `debug` or `release`, so you don't retype them. Its `binaryDir` setting names the folder for that build's files, such as `build/debug`.
Profiler
A tool that shows where a program spends its time, so you know what to speed up.
Projection
The member or function a ranges algorithm compares by, such as `&Item::cents` in `std::ranges::sort(items, {}, &Item::cents)`.
protected
An access level for class members that are hidden from outside code but usable in derived classes.
PUBLIC and PRIVATE
Keywords in `target_link_libraries`. `PRIVATE` means only this target needs the dependency, while `PUBLIC` also passes it on to every target linking this one.
Pure virtual function
A virtual function declared with `= 0` and no body, which derived classes must override.

R

RAII
The pattern where an object acquires a resource in its constructor and releases it in its destructor. Smart pointers, `lock_guard` and `jthread` all use it.
Ranges
The `std::ranges` versions of algorithms and views, which take whole containers instead of `begin()` and `end()` and accept projections.
Reference count
How many `std::shared_ptr`s point at one object. Copying adds one, destroying takes one away, and the object is deleted at zero.
Release build
Optimized code (`-O2`, or `-O3` in CMake's Release type) for real use, often many times faster than Debug.
Requires expression
A `requires(const T& t) { ... }` block listing code that must compile for a type. It's how `Priced` demands a `cents()` member.
reserve
A vector member that makes room for a given number of elements once, so many `push_back`s don't repeatedly move to bigger storage.
Rule of five
If you write any one of the destructor, copy operations or move operations, think about all five.
Rule of zero
If every member already copies and moves correctly, as `std::string` and `std::vector` do, write none of the special members.
rvalue
A temporary about to disappear, such as `std::string{"Hearth"}`, whose contents can be taken instead of copied.
rvalue reference
A reference `T&&` that binds only to rvalues, so overloading on it tells a function it was given a temporary.

S

Sampling
How most profilers work: many times a second they note which function is running, then report the busiest ones.
Scoped enumeration
An `enum class`: a type with a fixed list of named values written with the type name first, such as `ParseError::bad_quantity`. It doesn't convert to `int` by itself.
Shared pointer
`std::shared_ptr` allows several owners of one object, keeping a reference count and deleting the object when the last owner goes.
Sink parameter
A parameter taken by value that the function moves into storage. An lvalue argument costs one copy and a moved-in argument costs none.
Spurious wake-up
A thread waking from `wait` for no reason, with no notify. The predicate passed to `wait` makes it harmless.
Stack
Memory for local variables, which a function gets when it starts and gives back when its block ends.
std::accumulate
An algorithm from `<numeric>` that adds up a range starting from a given value. The start value's type is the total's type, so use `0LL` to avoid `int` overflow.
std::chrono
The library for measuring time. `steady_clock::now()` reads a clock that only moves forward, and subtracting two readings gives a duration whose `.count()` is the number.
std::deque
A standard container like a vector but fast at both ends, with operations such as `push_back`, `front` and `pop_front`. It is a natural base for a first-in, first-out queue such as the order `Queue`.
std::erase_if
A C++20 function that removes every element matching a test and returns how many it removed. It replaces the older `std::remove_if` plus `erase` pattern.
std::expected
A C++23 type holding either a value `T` or an error `E`, so the caller learns why something failed. Return success as a `T` and failure as `std::unexpected(error)`.
std::find_if
Algorithms that take a lambda: `find_if` returns an iterator to the first match (or `end()`), `count_if` counts matches, and `any_of` / `all_of` ask whether any or all elements match.
std::format
A function that builds text from a format string with `{}` placeholders, such as `{:>6.2f}` to right-align a number with two decimals.
std::from_chars
A function that parses a number from text without throwing and quickly. It returns where it stopped and an error code.
std::function
A type from `<functional>` that holds any callable with a given signature, such as `std::function<int(int)>`, so different lambdas can share one container, at a small cost per call. Calling an empty one throws `std::bad_function_call`.
std::list
A container that scatters its elements across memory, so a `std::vector` usually beats it.
std::move
A function from `<utility>` that moves nothing itself; it casts to an rvalue, saying "I'm done with this", so a move constructor can take the contents.
std::optional
A type holding either a value `T` or nothing, which you return as `std::nullopt`. Test it with `if (x)`, read it with `*x` or `->`, and use `.value_or` for a fallback.
std::ranges::to
A C++23 function that collects a view into a real container, such as a `std::vector` that owns its values.
std::scoped_lock
A lock that locks several mutexes at once, such as `std::scoped_lock lock{stock, sales};`, which avoids deadlock.
std::size_t
The unsigned type the library uses for sizes and indexes.
std::thread
Starts a thread running a function, usually a lambda. `.join()` waits for it, and destroying an unjoined `std::thread` stops the program.
std::unique_lock
A mutex lock that can be released and retaken. Condition variables need it because `wait` must unlock and relock.
Structured binding
Unpacking a pair or similar result into named variables, as in `auto [end, error] = std::from_chars(...)` or `for (const auto& [code, cents] : j.items())`.

T

Template argument deduction
The compiler working out `T` from a call's arguments, so `biggest(cents)` makes `T` an `int`.
Template parameter
The stand-in in `template <typename T>`, such as `T`, for a type (or a value) the caller picks.
Test fixture
A class derived from `::testing::Test` whose `SetUp()` runs before each `TEST_F` test, so tests share setup.
Test framework
A library that runs your tests and reports failures, such as GoogleTest.
Thread
One path of execution through a program. Every program starts with one running `main`, and more can run at the same time on different cores.
Thread-safe
Safe to use from several threads at once, like the `BlockingQueue`, which guards its data with a mutex.
ThreadSanitizer (TSan)
A compiler-built checker, enabled with `-fsanitize=thread -g`, that reports data races as they happen. It makes programs several times slower.
Toolchain file
A CMake script that sets up the build before anything else. vcpkg's `vcpkg.cmake` is loaded this way, through a preset.
transform (std::expected)
A `std::expected` member that runs a function on the value and wraps the result. On an error it skips the function and passes the error along.
Triplet
A vcpkg name for the platform to build for, such as `x64-mingw-static` for MSYS2's MinGW g++.
Type alias
A short name for a type, such as `using Reply = std::function<...>;`.

U

UBSan
A checker enabled with `-fsanitize=undefined` that reports undefined behavior such as signed overflow.
Undefined behavior
Code the C++ standard gives no meaning, so any result is possible, even a correct-looking one that hides the bug. A data race is one example.
Unique pointer
`std::unique_ptr` is the single owner of a heap object and deletes it in its destructor. It is move-only, so `std::move` transfers ownership.
Unit test
A small automatic check that calls one piece of your code with known input and verifies the result.

V

vcpkg
Microsoft's free, open-source C++ package manager. It builds each library from source with your compiler.
View
A lazy, non-owning window onto a range, such as `std::views::filter`. It does no work until iterated and dangles if the container it refers to is destroyed.
Virtual destructor
A destructor declared `virtual ~Discount() = default;` so that deleting through a base pointer runs the derived class's destructor too. Any class with virtual functions needs one.
Virtual function
A member function that derived classes can replace, with the version chosen at run time from the object's real type.

W

Weak pointer
`std::weak_ptr` watches a shared object without adding to its count. It breaks cycles of `shared_ptr`s, and `.lock()` gives a `shared_ptr`, empty if the object has gone.