Language basics
27 steps in 9 sets of C++.
C++ is where performance and abstraction refuse to compromise: game engines, browsers, trading systems, and most of the software that other software is built on. The language rewards knowing which decade of it you are writing — and modern C++ is a far better language than its reputation: auto, range-for, smart pointers, and the standard algorithms replaced most of the sharp edges the horror stories remember.
This tour covers the modern core: value types and references, the containers and iterators everything builds on, lambdas and the algorithm library, RAII and unique_ptr, classes with the rule of zero, and the string/stream toolkit. The encore ships complete programs. Every seed compiles as a translation unit under g++ -std=c++20 -Wall, and the encore runs start to finish.
Values & references
- Variables & autoDeclare the type when it matters, let
autodeduce it when the initializer already says it all. - References & constA reference is a second name for the same object;
const &is C++'s read-only borrow. - String basics
std::stringowns its characters and hands you concatenation, search, and slicing as methods.
Control flow
- If & switchGuard the weird input with
if, then letswitchfan the normal range out into cases. - Range-based forThe loop that walks a whole container with no index, no iterator, and no off-by-one.
- While & do-while
whiletests before every pass;do-whileruns the body once before it ever asks.
Containers
- Vector operations
std::vectoris the default container: a growable array with the whole toolkit attached. - Map lookup
std::mapkeeps keys sorted and gives you three ways in: subscript,contains, andfind. - Sets & uniqueness
std::setstores each value once, sorted, and itsinsertreports whether it did anything.
Functions & lambdas
- Function overloadingOne name, three signatures: the compiler picks the right
twicefrom the argument type alone. - Lambda capturesThe capture list decides what a lambda can see: a private copy with
[base], live access with[&total]. - Default argumentsTrailing parameters get fallback values, so one
joinserves three call shapes.
Algorithms
- Sorting with rangesC++20's
std::ranges::sorttakes the whole container and any ordering you hand it. - transform & accumulateMap then reduce, standard-library style:
std::transformsquares,std::accumulatesums. - find & countThree questions about a vector, each answered in one algorithm call instead of a hand-rolled loop.
Classes & RAII
- The rule of zeroWhen every member cleans up after itself, the class declares no destructor, no copy, no move: zero special members.
- Constructors & member initMembers initialize before the constructor body ever runs: the initializer list is the real assignment.
- unique_ptr ownershipOne owner at a time:
std::unique_ptrdeletes what it holds, and onlystd::movecan pass it on.
Strings & streams
- string_viewA window into someone else's characters: substrings with no copies, checked at compile time.
- String streamsBuild strings with
<<and parse them back with>>, no manual conversion in sight. - std::formatC++20's answer to printf: type-checked templates with alignment, precision, and bases.
Modern touches
- optional and value_orMaybe-a-value without sentinel numbers:
std::optionalturns bad input into a clean no. - Structured bindingsUnpack pairs and map entries into named variables — no more
.firstand.second. - Scoped enums
enum classkeeps enumerators out of the surrounding scope and off implicit int.
Encore
- word_freq.cppA word-frequency report over an inline passage, one
std::mapdoing the counting. - grade_report.cppAverages and bests per student, printed as an aligned table with
std::format. - temp_stats.cppMin, max, and mean over a dozen embedded readings, courtesy of
std::ranges.