Skip to content

C++20

C++20 (ISO/IEC 14882:2020) is the most influential release since C++11, introducing four "cornerstone" features: Concepts, Ranges, Coroutines, and Modules.

The Four Cornerstones

Concepts

Apply named constraints to template parameters, replacing SFINAE and static_assert:

cpp
template<typename T>
concept Sortable = requires(T a, T b) {
    { a < b } -> std::convertible_to<bool>;
};

void sort(Sortable auto& container);

Ranges

Lazy-evaluation-based pipeline data processing:

cpp
auto result = numbers
    | views::filter([](int n) { return n > 0; })
    | views::transform([](int n) { return n * n; })
    | views::take(10);

Coroutines

Low-level support for stackless coroutines (co_await, co_yield, co_return), providing language-level support for asynchronous programming and the generator pattern. High-level wrappers in the standard library (std::generator) were deferred to C++23.

Modules

A modular compilation system that replaces #include, addressing header compilation efficiency and macro pollution problems.

Other Important Features

FeatureDescription
<=> three-way comparison operatorAutomatic generation of comparison operators
consteval / constinitMore precise compile-time semantics
std::formatType-safe formatting library (Python-style)
std::spanNon-owning sequence view over contiguous memory
std::jthreadThread with automatic join
std::latch / std::barrier / std::counting_semaphoreSynchronization primitives
std::source_locationReplaces __FILE__/__LINE__
std::ranges algorithmsRange-based find, sort, transform
std::erase / std::erase_ifUniform container erasure
Calendars and time zonesMajor extensions to the chrono library

Compiler Support

CompilerSupport Status
GCC10+ (core features), 12+ more complete
Clang15+ (Modules still experimental)
MSVCVS 2022 (17.0)+

Further Reading

Released under the MIT License