C++ guides
Modern C++ guides: C++20 and C++23 features, compilers, build systems, and measured performance.
-
The loop variable every lambda shares
A short C++ program with a bug: the loop variable every lambda shares. The answer, the observed output, the fix, and the lesson are in this tutorial.
-
A sorted map backed by vectors (std::flat_map, C++23)
std::flat_map keeps keys sorted like a map but stores them in vectors, so iteration is cache-friendly and there is no per-node allocation.
-
A thread that stops itself cleanly (std::jthread)
std::jthread joins at destruction and carries a stop token, so the two classic thread bugs — a forgotten join and a thread with no way to stop — are both gone by construction.
-
enumerate instead of a manual counter (C++23 ranges)
std::views::enumerate pairs each element with its index, so the loop body never maintains a counter by hand.
-
A lazy pipeline with std::generator
A coroutine returning std::generator produces values on demand: nothing runs until the caller iterates, and nothing is stored.
-
One function instead of const/non-const overload pairs (deducing this)
An explicit object parameter lets one function see whether it was called on a const object, replacing the duplicated overload pair.
-
Constrain a function with a concept, in the parameter list
An abbreviated function template puts the constraint where the parameter is declared. A wrong argument type is a compile error naming the concept, not a page of template errors.
-
Return errors as values with std::expected
std::expected
carries either a value or an error, so error paths stay visible in the type instead of hiding in exceptions or out-parameters. transform maps the value and passes errors through untouched.