Last updated:2026-10-12
A Guide to C++20 New Features¶
In previous articles I covered a few important C++20 features here and there, for example:
This post will briefly list some of the more important features for reference, and explain why you should learn C++20 and what benefits it can bring to your code.
C++20 is the name of the ISO/IEC standard revision of the C++ programming language that follows C++17. C++ is a general-purpose, high-performance programming language widely used across application domains, including operating systems, browsers, and many other kinds of software.
C++20 introduces many new features and improvements designed to make C++ more expressive, more efficient, and easier to use. Some of the most important C++20 features include:
- Concepts: make template programming more intuitive, reliable, and easier to use. With concepts, we can write more expressive and readable code while getting better compile-time error checking and more precise automatic deduction.
- Coroutines: a way to write asynchronous code in a synchronous style, making it easier to write code that can be suspended and resumed without blocking the entire program.
- Modules: a new way to organize and reuse code that simplifies building and distributing large software projects.
- Ranges: introduces the ranges library (an extension and generalization of the algorithms and iterator libraries), providing a more intuitive, concise, and feature-rich way to process and manipulate collection data.
- Spaceship operator: a new operator for three-way ordering comparison of objects, making it easier to write code that compares and sorts complex data structures.
- constexpr lambdas: the ability to use lambdas as constexpr functions, allowing lambda expressions in more contexts, including constant expressions and template arguments.
- Designated initializers: a more expressive syntax for initializing structs and arrays, making it easier to specify the values of individual members of a struct or array.
C++20 also includes many other improvements and changes, such as additional library facilities, performance improvements, and better support for modern hardware and platforms. All in all, C++20 represents a major step forward for the C++ language and is expected to have a significant impact on how C++ is used and developed in the future.
The Benefits of C++20¶
C++20 introduces many new features and improvements aimed at the productivity and expressiveness of C++ code. Some benefits of C++20 include:
- Performance improvements: C++20 includes many changes and improvements aimed at the performance of C++ code. For example, C++20 introduced the
std::formatlibrary, a high-performance alternative toprintfandsprintffor string formatting. C++20 also includes improvements tostd::variantandstd::optionalthat can help reduce the overhead of using these types in some situations. In addition, C++20 introduced thestd::bit_castfunction, providing a safe and effective way to perform type conversions. - Better support for modern hardware and platforms: C++20 includes many changes and improvements that make it easier to write code optimized for modern hardware and platforms. For example, C++20 introduced the
std::atomic_reftype, which provides a way to perform atomic operations on non-atomic objects. C++20 also includes support for thestd::endiantype, allowing you to write portable code across architectures with different byte orders. In addition, C++20 introduced thestd::spantype, a way to represent a contiguous sequence of objects in memory that can be used to write code optimized for cache-friendly access patterns. - Modular programming: C++20 introduces support for modular programming, a new way of organizing code that lets developers split code into logically independent modules..
- And so on
Wrap-up¶
In short, C++20 is a major new version of the C++ programming language, introducing many new features and improvements aimed at the productivity and expressiveness of C++ code. Some of the key C++20 features include concepts, coroutines, modules, ranges, the spaceship operator, constexpr lambdas, designated initializers, and default member initializers for classes. These features can help improve the performance, flexibility, and modularity of C++ code, and make it easier to write code optimized for modern hardware and platforms.
If you are a C++ programmer, we encourage you to learn more about C++20 and start using its new features in your own code. C++20 is a powerful and versatile language that can help you write efficient, expressive, and maintainable code. By taking advantage of the new features and improvements C++20 introduces, you can boost your productivity and write code that better fits your project's needs.
Related Topics¶
- Getting Started with C++20 Coroutines | C++那些事
- C++20 channel in Practice | C++那些事
- C++20 Concepts | C++那些事
- C++20 constexpr and the Comma Expression | C++那些事
- C++20 Byte Order (endian) | C++那些事
- C++20 Lambda Expressions (Part 1) | C++那些事
- C++20 Modules | C++那些事
- C++20 Ranges Library | C++那些事
- C++20 std::span Design and Pitfalls | C++那些事
- C++20 [[likely]] and [[unlikely]] | C++那些事