C++
Welcome to the modern C++ guide, covering everything from RAII fundamentals to C++26 features.
Keywords (C++20+)
- alignas, alignof
- and, and_eq, bitand, bitor
- asm, auto
- bool, break
- case, catch, class, concept, const, constexpr, consteval, constinit
- continue, co_await, co_return, co_yield
- decltype, default, delete, do
- dynamic_cast, else, enum, explicit, export
- extern, false, final, float, for, friend
- goto, if, import, inline
- int, long, mutable, namespace
- new, noexcept, not, not_eq
- nullptr, operator, or, or_eq
- override, private, protected, public
- reflexpr, register, reinterpret_cast, requires
- return, short, signed, sizeof
- static, static_assert, static_cast, struct
- switch, template, this, thread_local
- throw, true, try, typedef, typeid, typename
- union, unsigned, using
- virtual, void, volatile, wchar_t
- while, xor, xor_eq
Pillars of C++
- RAII: acquire resources in constructors, release in destructors.
- Zero-cost abstractions: templates, inline functions, constexpr evaluations.
- Generic programming: templates, concepts, ranges.
- Object-oriented design: classes, inheritance, polymorphism, virtual dispatch.
- Functional features: lambdas, `std::function`, ranges views, coroutines.
Standard Library Highlights
- Containers: vector, array, deque, list, forward_list, set, map, unordered_map, unordered_set.
- Algorithms: sort, stable_sort, transform, accumulate, reduce, for_each, ranges::views.
- Utilities: optional, variant, any, expected (P2505), tuple, pair.
- Strings: string, string_view, format, filesystem paths.
- Concurrency: thread, jthread, mutex, shared_mutex, async, future, promise, atomic.
- Memory: unique_ptr, shared_ptr, weak_ptr, allocator-aware containers.
Modern Features to Know
- auto type deduction and ranged-for loops.
- Structured bindings and decomposition declarations.
- constexpr algorithms and consteval immediate functions.
- Modules and header units for faster builds.
- Concepts for readable template constraints.
- Coroutines (`co_await`, `std::generator`) for async pipelines.
- Spaceship operator (`<=>`) for three-way comparison.
- Ranges library for lazy, composable iteration.
Operators
- Arithmetic: + - * / % ++ --
- Comparison: == != < > <= >= <=>
- Logical: && || !
- Bitwise: & | ^ ~ << >>
- Assignment: = += -= *= /= %= &= |= ^= <<= >>=
- Pointer/reference: * & [] -> :: . .* ->*
- Type traits: static_cast, const_cast, reinterpret_cast, dynamic_cast.
Sample Patterns
- Use `std::span` for non-owning views of contiguous data.
- Prefer `std::unique_ptr` and `std::make_unique` over `new` / `delete`.
- Attach invariants with `gsl::not_null`, `std::optional`, and contracts (when available).
- Leverage `fmt::format` or `std::format` for typesafe text.
- Profile builds with sanitizers: address, thread, undefined behavior, leak.