Goals of C++ 23

Source: Zhihu, Author: Nanshan Yanyu Zhujiang TideLink: https://zhuanlan.zhihu.com/p/107360459

C++20 is the largest version ever, akin to constructing a beautiful skyscraper, but due to time constraints, the interior decoration is not yet complete, which feels like this:

Goals of C++ 23

The primary task of C++23 is, of course, to continue the interior decoration of the building, so C++23 should look like this:

Goals of C++ 23

C++23 has four highest priority features, all of which are supplements to the standard library rather than language-level features, namely: libraries related to coroutines, a modular standard library, executors, and networking.

Library support for coroutines

C++20 introduced the feature of stackless coroutines, preparing for better asynchronous programming. However, due to significant controversy over the implementation of coroutines in this version, the resolution for coroutines came very late, so there was not enough time to provide coroutine-related support libraries in C++20, such as std::generator, std::task, etc., which will need to be provided in C++23. With the support of these libraries, everyone will be able to write coroutines.

A modular standard library

C++20 introduced the modules feature, which theoretically greatly improves compilation speed. Developers can now organize their projects using modules, but the standard library itself is not modularized yet, and it is still not possible to import anything from the STL; this will have to wait until C++23.

Executors

The executor provides a set of general APIs for asynchronous and concurrent programming in C++. Related features have been discussed since 2012, and after many revisions, it was finalized in 2019. Currently, it is a very simple and easy-to-use model, unifying coroutines and threads, directly influencing the style of writing asynchronous code in the future.

The executor was originally intended to be included in C++20, but the standard committee is conservative, and another feature separated from the executor had not been validated before, so it was postponed to C++23. Since it has already been a 7-year wait, what’s another 3 years? The unfortunate part is for those features that depend on the executor, especially networking.

Given the current high level of completion, the executor may be confirmed for inclusion in C++23 within the next few months.

Networking

If the executor has taken over 10 years to have a chance to enter the C++ standard, then networking has waited a full 20 years.

Networking is a set of network APIs based on asio, and it is the most complete, highest quality, and most uniformly styled library among all C++ third-party network libraries (because it has only one author). The author proposed its inclusion in the C++ standard library as early as 2003, and it was only confirmed to be included in the standard library in 2023.

Networking depends on the executor, which has now been confirmed, so the asio code will also undergo some changes to encapsulate asynchronous APIs using the executor.

In addition to the four new features at the standard library level mentioned above, C++23 may also introduce some new language-level features, the outcome of which will depend on the progress of these features. C++23 will strongly recommend the following features, and if any of them are ready, they will be directly included in the C++ standard: Reflection, Pattern matching, and Contracts. Currently, these features are all progressing steadily.

—END—

Leave a Comment