typestar

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.

Start this tour

Values & references

  • Variables & autoDeclare the type when it matters, let auto deduce 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 basicsstd::string owns its characters and hands you concatenation, search, and slicing as methods.

Control flow

  • If & switchGuard the weird input with if, then let switch fan 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-whilewhile tests before every pass; do-while runs the body once before it ever asks.

Containers

  • Vector operationsstd::vector is the default container: a growable array with the whole toolkit attached.
  • Map lookupstd::map keeps keys sorted and gives you three ways in: subscript, contains, and find.
  • Sets & uniquenessstd::set stores each value once, sorted, and its insert reports whether it did anything.

Functions & lambdas

  • Function overloadingOne name, three signatures: the compiler picks the right twice from 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 join serves three call shapes.

Algorithms

  • Sorting with rangesC++20's std::ranges::sort takes the whole container and any ordering you hand it.
  • transform & accumulateMap then reduce, standard-library style: std::transform squares, std::accumulate sums.
  • 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_ptr deletes what it holds, and only std::move can 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::optional turns bad input into a clean no.
  • Structured bindingsUnpack pairs and map entries into named variables — no more .first and .second.
  • Scoped enumsenum class keeps enumerators out of the surrounding scope and off implicit int.

Encore

  • word_freq.cppA word-frequency report over an inline passage, one std::map doing 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.

The other C++ tours