The C++20 Revolution¶
C++20 is the biggest update since C++11, introducing features that fundamentally change how we write code.
Concepts: Constraining Templates¶
Concepts allow you to specify requirements for template arguments. This produces much better error messages than "template substitution failure" (SFINAE).
You can define your own concepts:
Ranges: Pipeable Algorithms¶
The Ranges library allows you to compose algorithms using the pipe operator (|), similar to Unix shells. It also handles "views" (lazy evaluation).
Modules: Goodbye Header Files¶
Modules promise faster build times and better isolation by replacing the textual inclusion of header files (#include).
Note: Compiler support for modules is still maturing.
Coroutines¶
Coroutines allow functions to be suspended and resumed. They are the foundation for async programming (generators, tasks).
co_await: Suspend execution until a task is done.co_yield: Return a value and suspend (generator).co_return: Finish the coroutine.
Three-way Comparison (<=>)¶
Also known as the "Spaceship Operator". It automatically generates ==, !=, <, <=, >, >=.
std::format¶
A type-safe, fast, and extensible alternative to printf and iostreams. Inspired by Python's f-strings.
Other Features¶
consteval: Functions that must run at compile-time.std::span: Non-owning view of contiguous memory.jthread: Auto-joining thread (stops on destruction).