C++ 26 committee progresses new features including contracts and ‘desperately needed’ reflection

C++ 26 committee progresses new features including contracts and ‘desperately needed’ reflection

Herb Sutter, Convener of the ISO/IEC C++ Technical Committee, reports that C++ 26 will have new features including contracts and reflection.

The committee met last week in Kona, Hawaii, the second meeting to determine what will be in the forthcoming standard. The committee aims to have the biggest features approved for pursuing early in the process. 

C++ is updated in a three-year cycle, and work on C++ 26 is well under way even though C++ 23 still has a status of “out for final ballot.”

Contracts are a language feature to implement design by contract, in which class methods define preconditions for calling the method, postconditions for the result, and valid state for class members, an approach first adopted by Bertrand Meyer for the Eiffel language in the mid-eighties and which has influenced other languages since.

The committee has approved a paper which defines a syntax for contracts, though Sutter adds that that “there are a handful of design questions still to decide, notably the semantics of implicit lambda capture, consteval, and multiple declarations.”

Reflection is the ability for processes to introspect their own types and behaviour at runtime. Languages such as C# and Java support reflection but C++ does not. A proposal to add static reflection to C++ 26 was adopted unanimously last week, as a “core of static reflection that is useful enough to solve many important problems, while letting us also plan to continue building on it further post-C++ 26,” Sutter wrote, adding that “we desperately need reflection in C++.”

Other features progressed include dense linear algebra based on the Basic Linear Algerbra Subprograms (BLAS) in the C++ Standard Library; a standard API for debugging support such as std:breakpoint(); SIMD (Single Instruction, Multiple Data) parallelism, and safety proposals for C++ “as proposed by Bjarne Stroustrup”, the inventor of C++.

C++ occupies an unusual position in programming languages, being widely used but also often criticised for being unsafe, over complex, and lacking modern features. Sutter himself has an experimental project called Cppfront whose goal is to “explore whether there’s a way we can evolve C++ itself to become 10x simpler, safer, and more toolable.” Google has sponsored another experiment called Carbon. The key problem is how to make improvements while also preserving compatibility with existing code.

Features such as reflection and contracts are likely to be welcomed by the C++ community; yet their appearance now (that is, in a forthcoming C++ 26) also underlines how the language, despite its complexity, has fallen behind others.