Skip to content
Tutorials Center
My learning

Topics

C++ Reference ยท Preprocessor, Tools and Concepts

What is coming in C++26

A preview of C++26: static reflection, contracts, pack indexing, inplace_vector, std::execution, saturating arithmetic, #embed and the _ placeholder.

C++26 is the next ISO standard after C++23. Its largest additions are static reflection (code that inspects types at compile time), contracts (preconditions and postconditions in the language), and std::execution (a framework for asynchronous work). It also includes many smaller changes that make everyday code shorter and safer.

Compilers are adding C++26 features one at a time, mostly behind -std=c++2c (GCC and Clang) or /std:c++latest (MSVC). Features and details can still shift during implementation, so treat this page as a preview. Our runner builds with -std=c++23, so almost everything here is read-only. A few small language features compile there as extensions with a warning, which is shown in the first example.

Terminal
g++ -std=c++2c main.cpp        # GCC 14+; the exact feature set depends on the version

Try it

C++ C++26 features GCC 15 accepts early (warnings are expected)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with std::cin or std::getline), it gets the next line from this box.

C++ C++23 code that does today what C++26 will standardize

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with std::cin or std::getline), it gets the next line from this box.

Compiler warnings from the first example look like 'delete' reason only available with '-std=c++2c'. They are the compiler telling you the feature is newer than the mode you chose.

Language features

Feature Idea Status on our runner
Static reflection (^^T, [: ... :], <meta>) Inspect and generate code from types, members and enumerators at compile time. Read-only: <meta> is not available.
Contracts (pre, post, contract_assert) Preconditions and postconditions checked at run time, with a configurable violation handler. Read-only.
Pack indexing (Ts...[0]) Pick a single element of a parameter pack by index. Read-only.
Placeholder _ Declare unused names more than once. Accepted as an extension (with a warning).
= delete("reason") Message when a deleted function is selected. Accepted as an extension (with a warning).
#embed Include the bytes of a file as an initializer list at preprocessing time. Accepted by GCC 15, but needs a file next to the source, so not usable online.
Structured bindings as conditions and packs if (auto [a, b] = f()) can be a condition; bindings can introduce a pack. Read-only.
Variadic friends friend Ts...; Read-only.
User-generated static_assert messages The message may be a constant expression such as a std::string_view. Read-only.
Trivial relocatability Marks types that can move by memcpy; lets containers grow faster. Read-only.
Erroneous behavior Reading an uninitialized variable is no longer arbitrary undefined behavior, but "erroneous behavior" with a defined fallback value. Read-only.
C++
// Reflection (C++26, not available online): list the enumerators of an enum
enum class Color { Red, Green, Blue };

template <typename E>
constexpr std::string_view to_name(E value) {
    template for (constexpr auto e : std::define_static_array(std::meta::enumerators_of(^^E))) {
        if (value == [:e:]) {
            return std::meta::identifier_of(e);
        }
    }
    return "?";
}
C++
// Contracts (C++26, not available online)
int divide(int a, int b)
    pre(b != 0)
    post(r : r * b <= a || a < 0)
{
    return a / b;
}

Library features

  • std::execution (senders and receivers): a model for composing asynchronous work and schedulers.
  • std::inplace_vector<T, N>: a vector with fixed capacity stored inside the object, with no heap allocation (useful in embedded and real-time code).
  • std::function_ref, std::copyable_function: non-owning and copyable callable wrappers.
  • Saturation arithmetic (std::add_sat, sub_sat, mul_sat, div_sat, saturate_cast): arithmetic that clamps at the limits.
  • std::hive: a container with stable element addresses and fast insertion and erasure.
  • Ranges and views: views::concat, views::cache_latest, views::to_input, and std::optional as a range.
  • std::submdspan, linear algebra (<linalg>), and <simd>.
  • Formatting and text: std::to_string for floating-point values that matches std::format, std::text_encoding, and std::format support for more types.
  • Hardening: a standardized "hardened" standard library mode that checks preconditions (such as vector::operator[] bounds) and terminates on violation.
  • Removals and deprecations: several long-deprecated features leave, for example parts of <codecvt> and some uses of volatile.

Usage notes

  • Do not ship on a draft. Features can change between a compiler's first implementation and the final ISO text. Use feature-test macros (__cpp_pack_indexing, __cpp_lib_inplace_vector, __cpp_lib_saturation_arithmetic, ...) and keep a fallback.
  • GCC and Clang get features at different times. Check each compiler's C++26 support table for the exact version before you plan on a feature.
  • Reflection changes library design. Serialization, enum-to-string, and command-line parsers that today need macros or code generators become ordinary library code.
  • Contracts are not exceptions. A contract violation calls a handler, and by default the program ends; the evaluation mode (ignore, observe, enforce) is chosen at build time.
  • Most C++26 features can be emulated today with C++23 helper functions, as the second example shows. Writing the helper with the standard name makes the switch later easy.