C++ — Modern Features Reference (C++20-23)

C++ — Modern Features Reference (C++20-23)

Overview

A structured reference of C++20 and C++23 features organised by use case / problem domain, not by standard version. The aim is to answer “what should I reach for here?” rather than “what was added in which standard?”

Features marked * appear in multiple categories.

Feature map (categories 1–4):

Feature map (categories 5–8):

Feature map (categories 9–10):

Source: Sagar @ Towards Dev (2026-04-14). Companion images in ingested/assets/.


Category 1 — Performance & Runtime Optimization

FeatureStdSummary
std::move_only_functionC++23No copy overhead for callables. Lighter than std::function
Ranges (Lazy Evaluation)C++20*Views lazily evaluated — no intermediate allocations/copies
std::jthread + stop_tokenC++20*Cooperative cancellation avoids wasteful polling & forced termination
Coroutines (co_await)C++20Stackless suspend/resume without thread overhead. Async I/O gains
std::assume_alignedC++20Alignment hint to compiler for SIMD vectorisation & cache perf
[no_unique_address](/wiki/nouniqueaddress/)C++20Empty base optimisation without inheritance. Smaller object layout
std::flat_map / flat_setC++23Contiguous memory layout for cache-friendly sorted containers
std::unreachable()C++23UB hint — lets compiler optimise dead branches & switch stmts
[likely](/wiki/likely/) / [unlikely](/wiki/unlikely/)C++20Branch prediction hints for hot paths

Category 2 — Compile-Time Computation

FeatureStdSummary
constevalC++20Guaranteed compile-time execution — immediate functions, no runtime path
constinitC++20Ensures constant initialisation. Prevents static init order fiasco
constexpr expandedC++20virtual, try/catch, dynamic_cast, union, new/delete now allowed in constexpr
constexpr further expandedC++23constexpr unique_ptr, optional, variant, cmath, bitset, more STL
if consteval {}C++23Branch on compile-time vs runtime context. Replaces is_constant_evaluated
static_assert(false, f(...))C++23Computed messages in static_assert — better diagnostics
Class-Type NTTPC++20*Structs/strings as template params. Compile-time config & DSLs
constexpr vector/stringC++20Heap allocation at compile time. Transient alloc in constexpr
is_constant_evaluated()C++20Detect compile-time context to pick optimised code paths

Category 3 — Readability & Expressiveness

FeatureStdSummary
Ranges pipe \| operatorC++20Composable, declarative data transformations via \| chaining
Designated InitializersC++20.field = value syntax for aggregates. Self-documenting init
std::formatC++20*Python-like formatting. Type-safe, readable alternative to printf/streams
std::print / std::printlnC++23Direct formatted output. No more cout chains or printf
operator<=> (Spaceship)C++20Auto-generates all 6 comparison operators from one declaration
using enumC++20Import enum values into scope. Cleaner switch/case on enums
Init-stmt in range-forC++20for(auto v = get(); auto& x : v) — tighter scoping, less boilerplate
Deducing thisC++23*Explicit object parameter. Kills CRTP boilerplate, enables recursion in lambdas
Multidim operator[]C++23m[x, y, z] instead of m[x][y][z]. Cleaner matrix/tensor access
auto(x) / auto{x}C++23Explicit decay-copy. Cleaner than static_cast or type repetition
Lambda improvementsC++20Template lambdas, [=, this], pack expansion in captures
auto Params (Abbrev Tmpl)C++20void foo(auto x) instead of template<class T> void foo(T x)

Category 4 — Safety & Correctness

FeatureStdSummary
std::spanC++20Non-owning view over contiguous memory. No raw ptr + size pairs
Concepts (Constraint Safety)C++20Catch type errors at call site, not deep in template instantiation
constinit (safety)C++20Prevents accidental dynamic init of global/static variables
std::expected<T, E>C++23Type-safe error handling without exceptions. Value-or-error pattern
[nodiscard("reason")](/wiki/nodiscardreason/)C++20Custom warning messages when return values are discarded
std::bit_castC++20Safe type punning — replacement for reinterpret_cast / memcpy
Paren Init for AggregatesC++20make_shared and emplace work with aggregates — no narrowing bugs
optional::and_then/or_elseC++23Monadic ops — chain operations on optional without null checks
std::source_locationC++20Type-safe __FILE__ / __LINE__. Better logging & diagnostics
std::stacktraceC++23Portable stack traces for debugging & error reporting
[assume(expr)](/wiki/assumeexpr/)C++23Assert invariants to compiler. Enables optimiser, documents intent
Implicit Move / NRVOC++20More contexts trigger implicit move — fewer accidental copies

Category 5 — Concurrency & Parallelism

FeatureStdSummary
Coroutines FrameworkC++20co_await, co_yield, co_return. Async without callback hell
std::jthreadC++20RAII thread — auto-joins on destruction. No more detach bugs
stop_token / stop_sourceC++20Cooperative cancellation protocol. Thread-safe request/check pattern
std::atomic<shared_ptr>C++20Lock-free shared_ptr operations. Safe concurrent shared ownership
counting/binary_semaphoreC++20Lightweight synchronisation primitive. Faster than mutex
std::latch / std::barrierC++20One-shot (latch) or reusable (barrier) thread synchronisation
std::atomic_refC++20Atomic ops on non-atomic objects. Flexible lock-free access
atomic::wait / notifyC++20Futex-style wait on atomics. Efficient spin-free waiting
std::osyncstreamC++20Synchronized output stream. No interleaved cout from threads

Category 6 — Metaprogramming & Type System

FeatureStdSummary
Concepts & ConstraintsC++20Named type requirements. Replace SFINAE with readable requires
requires {} expressionsC++20Inline constraint checks: valid expressions, type requirements
Deducing this (CRTP killer)C++23*Replaces CRTP pattern. Recursive lambdas, simplified mixins
std::type_identityC++20Prevent deduction on specific parameters. Control template args
std::remove_cvrefC++20Combined cv + ref removal trait. Simpler than chained traits
std::common_referenceC++20Foundation for ranges/concepts. Unifies proxy & value references
Class-Type NTTP (meta)C++20*Compile-time strings, regex, FSMs as template arguments
Lambdas in unevaluated ctxC++20Lambdas in decltype, sizeof. Enables new metaprogramming idioms
std::to_underlyingC++23Convert enum to underlying type. Replaces static_cast patterns

Category 7 — Generic Programming & Ranges

FeatureStdSummary
std::ranges libraryC++20*Views, adaptors, projections. Composable algorithm pipelines
Range views (20 types)C++20filter, transform, take, drop, split, join, reverse, elements…
Standard Concepts LibraryC++20same_as, derived_from, integral, invocable, sortable, ranges::…
New range viewsC++23zip, chunk, slide, stride, repeat, cartesian_product, as_rvalue…
ranges::to<Container>C++23Materialise a view into a concrete container — completes the pipeline
ranges::fold_left/rightC++23Proper fold algorithms. Explicit initial value, replaces accumulate
Constrained algorithmsC++20ranges::sort, find etc. take ranges directly + projections
Sentinel & SubrangeC++20End iterator can differ from begin. Null-term strings, infinite ranges
ranges::contains/starts_withC++23Long-missing algorithms. No more find != end patterns

Category 8 — Library & Utilities

FeatureStdSummary
std::mdspanC++23Multidimensional array view. Customisable layouts for HPC/ML
std::generator<T>C++23Coroutine-based lazy sequence. First standard coroutine type
chrono Calendar & TZC++20year, month, day, time zones, UTC, TAI clocks. Full date/time API
<bit> utilitiesC++20popcount, countl_zero, rotl, rotr, has_single_bit, bit_ceil/floor
std::byteswapC++23Portable byte order reversal. Endianness conversion utility
string::contains()C++23Finally: str.contains("sub") instead of find != npos
starts_with / ends_withC++20String and string_view prefix/suffix checks
std::endianC++20Compile-time byte order detection. Portable network/file I/O
std::bind_backC++23Bind trailing arguments. Companion to std::bind_front (C++20)

Category 9 — I/O, Formatting & Text

FeatureStdSummary
std::formatC++20*Type-safe, extensible formatting. "{:>10.2f}" with custom formatters
std::print / printlnC++23Direct UTF-8 output to stdout. Handles Unicode correctly on Windows
format_to / format_to_nC++20Format directly to output iterator. Avoids temp string allocation
std::osyncstream (I/O)C++20Atomic output operations. Thread-safe formatted output
Formatted range outputC++23std::format("{}", vec) — auto-formats containers & ranges
char8_t / u8stringC++20Distinct UTF-8 type. Prevents mixing encodings accidentally

Category 10 — Modularity & Build System

FeatureStdSummary
Modules (import/export)C++20Replace #include. Faster builds, isolation, no macro leakage
Module PartitionsC++20Split large modules into internal units. Incremental compilation
Header UnitsC++20import <iostream>; — bridge to modules from legacy headers
import std;C++23One import for entire standard library. Massive compile speedup
import std.compat;C++23Includes C library names in global namespace. Smooth migration
Feature Test MacrosC++20__cpp_concepts, __cpp_modules etc. Portable feature detection

Cross-Category Features (appear in 3+ categories)

From the cross-category diagram:

  • Concepts — touches Performance, Compile-Time, Safety, Metaprogramming, Generic Prog.
  • Ranges — touches Performance, Readability, Generic Prog., Library/Utilities
  • Coroutines — touches Performance, Concurrency, Library/Utilities
  • Deducing this — touches Readability, Metaprogramming, Generic Prog.
  • Formatting (std::format) — touches Readability, I/O & Formatting, Modularity/Build
  • constexpr family — touches Compile-Time, Safety, Metaprogramming

Decision Flowchart (C++20/23 Feature Selection)

The source includes a flowchart for choosing features. Decision tree summary:

  1. Performance problem? → Ranges (lazy), flat_map, assume_aligned, [likely](/wiki/likely/), coroutines (async I/O)
  2. Compile-time computation?consteval > constexpr > constinit
  3. Error handling without exceptions?std::expected<T,E> + monadic ops
  4. Thread management?std::jthread + stop_token + std::latch/barrier
  5. Type constraints on templates? → Concepts + requires expressions
  6. Generic algorithms over containers?std::ranges + constrained algorithms
  7. Formatted output?std::format (C++20) / std::print (C++23)
  8. Multidimensional data?std::mdspan
  9. Lazy sequences?std::generator<T> (C++23)
  10. Build isolation / compile speed? → Modules (import std;)

Further Reading (from source)

Key deep-dive articles by Sagar @ Towards Dev covering features in this map:

  • Concepts & Templates, std::span, Modules migration, Ranges/Views, Coroutines (parts 1-3), std::expected, std::mdspan, std::flat_map, Deducing this / CRTP, std::jthread, atomic improvements, std::format/print, constexpr evolution, <bit> header, branch prediction hints

See Also

Trending Tags