New C++ Release: What Has Changed in the Programming Language
The International C++ Standardization Committee (ISO/IEC JTC1/SC22/WG21) has officially approved the next version of the standard — C++23. This release brings long-awaited improvements that make the language safer, more expressive, and more convenient for developing both system and application software. We tell you about the most significant innovations.
Main Changes in C++23
1. std::print — Formatted Output Without Extra Effort
One of the most notable features is the introduction of the std::print function. Now, to output to the standard stream, you don't need to write cumbersome constructs with std::cout or use printf with the risk of type errors. std::print works based on std::format, ensuring type safety and readability:
- Automatic formatting of numbers, strings, and user-defined types.
- Support for locales and Unicode.
- Speed close to
printf, but without memory leaks.
2. Improved Work with Coroutines
Coroutines, first introduced in C++20, have received a number of fixes and additions. In C++23, the syntax for declaring asynchronous functions has been simplified, and support for std::generator has been added — a new type for creating sequences of values on the fly:
- Generators allow writing lazy computations without manual state management.
- The amount of boilerplate code for working with coroutines has been reduced.
3. Modules — Stability and Performance
Although modules were introduced in C++20, their implementation in compilers left much to be desired. The new standard clarifies the rules for export and import, which has led to:
- Reduction of compilation time for large projects by 2–3 times.
- Full compatibility with header files (hybrid mode).
- The ability to create modules for the standard library (experimental).
4. New Capabilities of constexpr and consteval
Expanding the context of constant expressions is one of the main goals of C++ development. In C++23, constexpr is allowed for:
- Dynamic memory allocation (
std::vectorandstd::string). - Calling virtual functions.
- Working with floating-point numbers without loss of precision.
This allows more and more computations to be performed at compile time, speeding up runtime.
5. The [[assume]] Attribute — Hints for the Optimizer
The new attribute [[assume(expression)]] tells the compiler that the expression is true at a given point in the code. This provides:
- More aggressive optimizations (branch elimination, loop unrolling).
- Increased performance in critical sections (game engines, embedded).
6. Simplification of Multithreading
New types for synchronization have been added: std::counting_semaphore with improved performance and std::latch for one-time barriers. Additionally, support for std::mdspan