C++26 standard approved

The ISO C++ language standardization committee has approved the final version of the specification that forms the international standard "C++26." The features presented in the specification are already partially supported in the GCC, Clang, and Microsoft Visual C++ compilers. Standard libraries supporting C++26 have been implemented within the Boost project.

Over the next two months, the approved specification will undergo a document preparation phase, during which editorial corrections will be made to address spelling errors and typos. In early November, the final version of the document will be submitted to ISO for publication under the formal name ISO/IEC 14882:2026.

Key features of C++26:

  • Contract programming elements (Contracts) have been implemented, allowing you to define formal interface specifications using three new operators: pre (precondition), post (postcondition), and contract_assert (assertion check). The "pre" operator defines preconditions that must be met before a call (input validation); "post" defines conditions that must be met after execution (output requirements); contract_assert defines conditions for raising exceptions. This feature will be available in GCC 16. int f(const int x) pre (x != 1) // input requirements post (r : r == x && r != 2) // result requirements; r is the value with the result { contract_assert (x != 3); return x; }
  • Reflection support has been added, allowing program elements to be observed and modified at compile time. New operators "^^" for obtaining metainformation about a grammar construct and "[:…:]" for performing the inverse transformation have been added. The std::meta library is provided for transforming and processing the information obtained during inspection, and such features as calculations with constants are available. Reflection support will be added in GCC 16. constexpr int i = 42, j = 42; constexpr std::meta::info r = ^^i, s = ^^i; static_assert(r == r && r == s); static_assert(^^i != ^^j); // 'i' and 'j' have different values. static_assert(constant_of(^^i) == constant_of(^^j)); // 'i' and 'j' are the same static_assert(^^i != std::meta::reflect_constant(42)); // different from the value 42
  • Added 'template for' for iterating over elements such as parameter packs, tuple-like objects, and reflection results (metaobjects) at compile time in the style of a regular for loop. When executing 'template for', the loop body is expanded for each element, and each iteration is processed in a separate scope in which the variable changing in the loop is constant. In the context of reflection, 'template for' can be used to iterate over properties of classes or enums. This feature will be available in GCC 16. void f() { template for (constexpr int I : std::array{1, 2, 3}) { static_assert(I < 4); } } will expand to: void f() { { constexpr auto&& __range = std::array{1, 2, 3}; constexpr auto __begin = __range.begin(); constexpr auto __expansion-size = __range.end() β€” __begin; // 3 { constexpr int I = *(__begin + 0); static_assert(I < 4); } { constexpr int I = *(__begin + 1); static_assert(I < 4); } { constexpr int I = *(__begin + 2); static_assert(I < 4); } } }
  • Added std::execution framework for asynchronous and parallel code execution. It provides scheduler objects, which define the work scheduler (thread, thread pool, GPU, event loop), sender objects, which define the work to be executed, and receiver objects, which handle the result. using namespace std::execution; scheduler auto sch = thread_pool.scheduler(); sender auto begin = schedule(sch); sender auto hi = then(begin, []{ std::cout < "Hello world! Have an int."; return 13; }); sender auto add_42 = then(hi, [](int arg) { return arg + 42; }); auto [i] = this_thread::sync_wait(add_42).value();
  • The std::simd library has been added for parallelizing data operations using SIMD instruction sets such as AVX-512 and NEON using the standard C++ type system. std::simd a = {1.0f, 2.0f, 3.0f, 4.0f}; std::simd b = {5.0f, 6.0f, 7.0f, 8.0f}; std::simd result = a + b;
  • An implementation of a variable-size vector (array) std::inplace_vector is proposed. It is allocated on the stack, the size of which is determined at compile time. The API is similar to std::vector, but the array elements are stored internally, not on the heap. inplace_vector a(10); inplace_vector b(std::move(a)); assert(a.size() == 10);
  • The "#embed" directive has been added for embedding binary resources into code. const unsigned char icon_display_data[] = { #embed "art.png" };
  • Added support for generating and handling exceptions at compile time when errors occur in the constexpr context. constexpr std::optional checked_divide(unsigned n, unsigned d) { try { return divide(n, d); } catch (...) { return std::nullopt; } } constexpr date parse_date(std::string_view input) { auto [correct, year, month, day] = ctre::match<β€œ([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})”>(input); if (!correct) { throw incorrect_date{input}; } return build_date(year, month, day); }
  • The std::hive data structure has been implemented for unordered data storage and reuse of memory freed by deleted elements. The structure is optimized for workloads with high-intensity addition and deletion of elements in arbitrary order. Unlike arrays, deleting an element in std::hive does not shift other elements, but rather marks the deleted element as empty, and then fills the vacated position when a new element is added.
  • Added std::linalg library with BLAS-based API for linear algebra.
  • Added support for the Hazard Pointer synchronization mechanism, which prevents the release of memory for objects being accessed by other threads without locking. When an object is deleted, it is only marked as deleted, but the memory occupied by the object is released only after all threads have released the hazard pointer set during access to the object.
  • Added support for the RCU (Read-Copy Update) synchronization mechanism. Write operations create a new instance of the object, while read operations don't block, but continue to work with the old instance. After the change is complete, the new instance becomes active, and new read operations are performed on it, while the old instance is deleted after the threads reading it complete.
  • Changes have been made to strengthen the standard library's safety, such as checking for valid values ​​and buffer overruns. For example, when accessing the element "constexpr reference operator[](size_type idx) const;", a check for the condition "idx < size()" is added.
  • The ability to use the constexpr keyword with a variant of the new operator (placement new) to place an object into pre-allocated memory at compile time is provided.
  • Added support for structured bindings in the "constexpr" context, meaning that references to constant expressions can now be constant expressions themselves. Support is implemented for arrays and simple structures. constexpr int arr[] = {1, 2}; constexpr auto [x, y] = arr;
  • Structured bindings now support the "..." syntax to specify packs that capture the remaining number of elements in the assignment sequence. auto [x,y,z] = f(); // variables x, y, z will contain the three elements returned by f(). auto [...xs] = f(); // package xs will contain all elements returned by f(). auto [x, ...rest] = f(); // x will contain the first element, and rest will contain the rest. auto [x, y, ...rest] = f(); // x will contain the first element, y will contain the second, and rest will contain the third. auto [x, ...rest, z] = f(); // x will contain the first, rest will contain the second, and z will contain the third.
  • Added support for "Trivial Relocatability" of types, which allows optimizing the movement of objects of a given type by cloning them in memory without calling constructors or destructors. The memberwise_trivially_relocatable and memberwise_replaceable properties are implemented for classes, and the trivially_relocate_at and trivially_relocate functions are added for low-level movement of one or more objects.
  • Support has been implemented for attaching the main() function to a global module and defining the main() function in named modules.
  • Added the variable operator "friend" ("friend Ts...").
  • Implemented attributes for structured bindings;
  • Added syntax '= delete("reason")'.
  • The basic character set includes "@", "$", and "`".
  • The ability to use structured binding as a condition in if and switch statements is provided.
  • Added the ability to use several placeholder variables with the name β€œ_” in one scope, for example, the following constructions are now correct: struct S { int _, _; }; void func() { int _, _; } void other() { int _; // previously a warning was displayed in -Wunused mode }
  • It is possible to use string literals in a context in which they are not used to initialize a character array and do not end up in the resulting code, but are used only at compile time for diagnostic messages and preprocessing, for example, as parameters of directives and attributes _Pragma, asm, extern, static_assert, [[deprecated]] and [[nodiscard]].
  • Added built-in functions: "__builtin_is_within_lifetime" to check if an alternative is active in unions and "__builtin_is_virtual_base_of" to check if the base class is virtual.
  • Implemented trivial infinite loops without undefined behavior.
  • Ensured that an error is displayed when deleting a pointer to an incomplete type.
  • The syntax for defining variadic parameters with an ellipsis without a preceding comma (for example, when specifying "void e(int…)" instead of "void e(int, …)") has been deprecated.
  • The use of macros to declare modules is prohibited.
  • Implicit conversions of enumerated values ​​in arithmetic calculations have been deprecated. int main() { enum E1 { e }; enum E2 { f }; bool b = e <= 3.7; // deprecated int k = f - e; // deprecated int x = +f - e; // OK }
  • Direct array comparison support has been discontinued. int arr1[5]; int arr2[5]; bool same = arr1 == arr2;
  • The is_trivial template class has been deprecated.

    Source: opennet.ru
Buy reliable hosting for sites with DDoS protection, VPS VDS servers πŸ”₯ Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster