C++ 26 Final Draft

The C++ standard board (ISO 14882) just met earlier this month to ratify the final draft of the C++ 26 standard. You can think of the final draft like a feature freeze as a product moves from beta to release candidate and we now have to wait for compiler vendors to implement the new standards. Several exciting new features just got added to the standard including contract programming, asynchronous sender/receiver and perhaps most importantly the new static reflection capabilities.

The new reflection details as described by Herb Sutter:

I’m positive that for many years to come we’ll be looking back at today, the day reflection first was adopted for standard C++, as a pivotal date in the language’s history. Reflection will fundamentally improve the way we write C++ code, expand the expressiveness of the language more than we’ve seen in at least 20 years, and lead to major simplifications in real-world C++ toolchains and environments. Even with the first partial reflection capability we have today, we will already be able to reflect on C++ types and use that information plus plain old std::cout to generate arbitrary additional C++ source code that is based on that information and that we can compile and link into the same program as it’s being built. (In the future we’ll also get token injection to generate C++ source right within the same source file.) But we can generate anything: Arbitrary binary metadata, such as a .WINMD file. Arbitrary code in other languages, such as Python or JS bindings automatically generated to wrap C++ types. All in portable standard C++.

This is a Big Hairy Deal. Look, everyone knows I’m biased toward saying nice things about C++, but I don’t go in for hyperbole and I’ve never said anything like this before. Today is legit unique: Reflection is more transformational than any 10 other major features we’ve ever voted into the standard combined, and it will dominate the next decade (and more) of C++ as we complete the feature with additional capabilities (just as we added to constexpr over time to fill that out) and learn how to use it in our programs and build environments.

You can see an example of the new reflection capabilities from InfoQ showcasing turning an enum into string values at compile time:

enum Color { red, green, blue }; 

static_assert(enum_to_string(Color::red) == "red");

template <typename E> 

template <typename E>

    requires std::is_enum_v<E>

constexpr std::string enum_to_string(E value) {

    template for (constexpr auto e : std::meta::members_of(^E)) {

        if (value == [:e:]) {

            return std::string(std::meta::name_of(e));

        }

    }

    return "<unnamed>";

}

Key Links

Herb Sutter C++ 26 Blog

InfoQ Article

C++ Standard Homepage

You can learn more about the new features coming in C++ 26 in the video below.

Scroll to Top