C++ 23 to introduce module support

Starting with the standard library, modules promise to improve both compilation speed and how C++ developers organize code.

C++ 23 to introduce module support
M-A-U / Getty Images

C++ 23, the planned next version of the C++ programming language due to be finalized in 2023, is set to move forward with support for a standard library module and faster compilation.

The upgrade to the language is likely to include a standard library module, called std, and some support for coroutines, language designer Bjarne Stroustrup said. With the standard library module, “Hello World” becomes as follows:

import std:
int main()
   Std::cout<< "Hello, World!\n";

This will compile 10 times faster than the old version using #include <iostream>, Stroustrup said.

Modules not only give improved compilation speed and better code hygiene, but also unify source organization of ordinary functions and templates, Stroustrup noted. The .h/.cpp distinction disappears and C++ source code is fundamentally simplified. “Eventually, modules will be the most significant improvement ever to the way we organize our code,” he said. 

C++ 23, which is being developed under the ISO (International Organization for Standardization), will have many minor improvements, some of which will not seem minor, Stroustrup said. He noted that it was never supposed to be a major upgrade of C++ the way C++ 11 and C++ 20 were. Rather, it was supposed to complete C++ 20 and hopefully ship a few significant features.

However, the pandemic forced a limit on ambitions. “It has been difficult to hold good design discussions virtually, and many people believe the lack of face-to-face contact has been a great handicap,” Stroustrup said. As a result, features such as pattern matching, contracts, and a general model for concurrency (executors) will have to wait until C++ 26.


Copyright © 2022 IDG Communications, Inc.