User:Moondezmon/C++23 Draft

C++23 is the informal name for the next version of the ISO/IEC 14882 standard for the C++ programming language that will follow C++20. The final draft of this version is N4950.

In February 2020, at the final meeting for C++20 in Prague, an overall plan for C++23 was adopted: planned features for C++23 are library support for coroutines, a modular standard library, executors, and networking.

The first WG21 meeting focused on C++23 was intended to take place in Varna in early June 2020, but was cancelled due to the COVID-19 pandemic, as was the November 2020 meeting in New York and the February 2021 meeting in Kona, Hawaii. All meetings until November 2022 were virtual while the November 2022 meeting until the final meeting on February 2023 was hybrid. The standard was technically finalized by WG21 at the hybrid meeting in Issaquah in February 2023.

Modern "Hello, world" Example
After many library changes applied to the working draft, the new "Hello, world" program will be:

Features
Changes that have been accepted into C++23 include:

Language

 * explicit  object parameter
 * multidimensional subscript operator
 * static call and subscript operators
 * simplifying implicit move
 * and
 * new preprocessor directives:
 * and
 * extending the lifetime of some temporaries in range-based for loop
 * new standard attribute
 * class template argument deduction from inherited constructors
 * labels at the end of the compound statement
 * alias declarations in init-statements
 * literal suffixes for  and the corresponding signed type
 * extended floating-point types with literals (conditionally supported)
 * optional  from nullary lambda expressions
 * attributes on lambda expressions
 * changes:
 * non-literal variables, labels, and s in   functions
 * allowing  and   variables in   functions that are usable in constant expression
 * function does not need its return type and parameter types to be literal type
 * it is now possible to write a  function for which no invocation satisfies the requirements of a core constant expression
 * narrowing contextual conversions to  in   and
 * trimming whitespaces before line splicing
 * make declaration order layout mandated
 * delimited escape sequences
 * named universal character escapes
 * text encoding changes:
 * support for UTF-8 as a portable source file encoding
 * consistent character literal encoding
 * character sets and encodings
 * consistent character literal encoding
 * character sets and encodings

Standard Library Module Support

 * standard library modules  and

Coroutine Library Support

 * synchronous coroutine  for ranges

General Utilities Support

 * result type
 * monadic operations for and
 * utility function  to get the underlying value of enum
 * move-only callable wrapper
 * : a function to mark unreachable code
 * made  compatible with other tuple-like objects
 * specialization for  yielding reference types
 * adding default arguments for 's forwarding constructor
 * : a function to mark unreachable code
 * made  compatible with other tuple-like objects
 * specialization for  yielding reference types
 * adding default arguments for 's forwarding constructor

Compile-time Support

 * support for:
 * for some  functions
 * for integral overloads of  and
 * metaprogramming utilities:
 * type traits,  ,  , and.
 * adding move-only types support for comparison concepts
 * metaprogramming utilities:
 * type traits,  ,  , and.
 * adding move-only types support for comparison concepts

Iterators, Ranges, and Algorithm Support

 * new range conversion function
 * new constrained ranges algorithm:
 * and other variants
 * rangified versions of,  , and
 * range fold algorithms
 * new, a helper for defining user-defined range adaptor closures
 * new range adaptors:
 * and other variants
 * and other variants
 * rectifying constant iterators, sentinels, and ranges, that is,  and other similar utilities returning constant iterators should be fully guaranteed even for shallow-const views (such as  )
 * ranges iterators as inputs to non-ranges algorithms
 * relaxing range adaptors to allow for move only types
 * making multi-param constructors of some views
 * rectifying constant iterators, sentinels, and ranges, that is,  and other similar utilities returning constant iterators should be fully guaranteed even for shallow-const views (such as  )
 * ranges iterators as inputs to non-ranges algorithms
 * relaxing range adaptors to allow for move only types
 * making multi-param constructors of some views
 * rectifying constant iterators, sentinels, and ranges, that is,  and other similar utilities returning constant iterators should be fully guaranteed even for shallow-const views (such as  )
 * ranges iterators as inputs to non-ranges algorithms
 * relaxing range adaptors to allow for move only types
 * making multi-param constructors of some views
 * rectifying constant iterators, sentinels, and ranges, that is,  and other similar utilities returning constant iterators should be fully guaranteed even for shallow-const views (such as  )
 * ranges iterators as inputs to non-ranges algorithms
 * relaxing range adaptors to allow for move only types
 * making multi-param constructors of some views
 * relaxing range adaptors to allow for move only types
 * making multi-param constructors of some views

Memory Management Support

 * and  for C interoperability
 * and
 * explicit lifetime management function  for implicit-lifetime types
 * disallowing user specialization of

String and Text Processing Support

 * new member functions and changes in string types:
 * and
 * disabling construction from  for   and
 * explicit range constructor for
 * rvalue reference overload of  for efficient slicing
 * formatting ranges, tuples, escaped presentation of characters and strings,, and stacktraces.
 * formatting ranges, tuples, escaped presentation of characters and strings,, and stacktraces.

Diagnostic Support

 * stacktrace library

I/O Support

 * formatted output functions  and   from new header
 * spanstream library ( -based string stream) from new header
 * a support for exclusive mode in s

Containers Support

 * multidimensional-span
 * constructability and assignability of containers from other compatible ranges
 * flat set and flat map container adapters
 * non-deduction context for allocators in container deduction guides
 * heterogeneous erasure overloads for associative containers
 * allowing iterator pair construction in stack and queue
 * requiring  and   to be trivially copyable

C-Compatibility Support

 * new header

Language defect reports

 * C++ identifier syntax using Unicode Standard Annex 31
 * allowing duplicate attributes
 * changing scope of lambda trailing return type
 * making overloaded comparison operators less breaking change
 * undeprecating volatile compound assignments
 * fixing the compatibility and portability of
 * relaxing requirements on  to match existing practices
 * allowing some pointers and references of  or unknown origin in constant expressions
 * introduction of immediate-escalating functions promoted to immediate functions
 * allowing  in uninstantiated template contexts

Library defect reports

 * changes in ranges library:
 * conditionally borrowed ranges
 * repairing input range adaptors and
 * relaxing the constraint on
 * renamed  to   and new
 * removed  constraint from concept
 * view with ownership and new
 * fixed
 * changes in text formatting library:
 * compile-time format string checks
 * reducing binary code size of
 * fixing locale handling in chrono formatters
 * improving width estimation and fill character allowances of
 * use of forwarding references in format arguments to allow non-const-formattable types
 * fully    and
 * supporting types derived from  in
 * supporting types derived from  in

Removed features and deprecation
Removed features:
 * Garbage Collection Support and Reachability-Based Leak Detection. It was added to the standard since C++11 but no compilers support this feature until C++23.
 * Mixed wide string literal concatenation.
 * Non-encodable wide character literals and multicharacter wide character literals.

Deprecated features:
 * and

Reverted deprecated features:
 * Use of comma operator in subscript expressions was no longer deprecated but the semantics has been changed to support overloadable n-adic.
 * C headers (The corresponding  headers for compatilibity with C)

Published as Technical Specifications

 * Concurrency TS v2

Compiler support

 * GCC added partial, experimental C++23 support in 2021 in version 11 through the option  or   It also has an option to enable GNU extensions in addition to the experimental C++23 support,.

History
In the absence of face-to-face WG21 meetings, the following changes were applied after several virtual WG21 meetings, where they were approved by straw polls.

The following were added after the virtual WG21 meeting of 9 November 2020, where they were approved by straw polls:
 * Literal suffixes for  and the corresponding signed type
 * A member function for  and, to check whether or not the string contains a given substring or character
 * A stacktrace library, based on Boost.Stacktrace
 * A type trait
 * The header, for interoperability with C atomics

After the virtual WG21 meeting of 22 February 2021, following features are added where they were approved by straw polls:
 * Removing unnecessary empty parameter list from lambda expressions.
 * Repairing input range adaptors and.
 * Relax the requirements for.
 * for classes that are derived from.
 * Locks lock lockables.
 * Conditionally borrowed ranges.

After the summer 2021 ISO C++ standards plenary virtual meeting of June 2021, new features and defect reports were approved by straw polls:
 * Consteval if.
 * Narrowing contextual conversions to.
 * Allowing duplicate attributes.
 * -based string-stream.
 * and.
 * constexpr for, , and.
 * Iterators pair constructors for (stack) and  (queue).
 * Few changes of the ranges library:
 * Generalized and  for arbitrary ranges.
 * Renamed to  and new.
 * Relaxing the constraint on.
 * Removing constraint from concept.
 * Range constructor for.
 * Prohibiting and  construction from nullptr.
 * Improvements on.
 * Adding default arguments for 's forwarding constructor.
 * Adding default arguments for 's forwarding constructor.

After the autumn 2021 ISO C++ standards plenary virtual meeting of October 2021, new features and defect reports were approved by straw polls:
 * Non-literal variables, labels, and gotos in functions, but still ill-formed to evaluate them at compile-time.
 * Explicit this object parameter.
 * Changes on character sets and encodings.
 * New preprocessors: and . Both directives were added to C23 (C language update) and GCC 12.
 * Allowing alias declarations in init-statement.
 * Overloading multidimensional subscript operator (e.g. ).
 * Decay copy in language: or.
 * Changes in text formatting library:
 * Fixing locale handling in chrono formatters.
 * Use of forwarding references in format arguments to allow -like types.
 * Addition of type alias which is equivalent to.
 * Changes in ranges library:
 * Refined definition of a view.
 * Replacing function template with alias templates, , and customization point object.
 * range adaptor family:
 * (and being equivalent to )
 * (and being equivalent to )
 * Monadic operations for.
 * Member function template.
 * Printing volatile pointers.
 * Heterogeneous erasure overloads for associative containers.
 * Every specialization of and  is trivially copyable.
 * Adding conditional specifications to.
 * Revamped specification and use of integer-class types.
 * Clarify C headers. "The headers are not useful in code that is only required to be valid C++. Therefore, the C headers should be provided by the C++ standard library as a fully-supported, not deprecated part, but they should also be discouraged for use in code that is not polyglot interoperability code. [..] This proposal makes the C headers no longer deprecated, so there is no formal threat of future removal. The effective discouragement to use the C headers in pure C++ code is now spelled out explicitly as normative discouragement."
 * Every specialization of and  is trivially copyable.
 * Adding conditional specifications to.
 * Revamped specification and use of integer-class types.
 * Clarify C headers. "The headers are not useful in code that is only required to be valid C++. Therefore, the C headers should be provided by the C++ standard library as a fully-supported, not deprecated part, but they should also be discouraged for use in code that is not polyglot interoperability code. [..] This proposal makes the C headers no longer deprecated, so there is no formal threat of future removal. The effective discouragement to use the C headers in pure C++ code is now spelled out explicitly as normative discouragement."

After the virtual WG21 meeting of 7 February 2022, the following features are added where they were approved by straw polls:
 * Allowed attributes on the function call operator of a lambda
 * for  and
 * Function to mark unreachable code
 * A type trait to detect reference binding to temporary
 * Making
 * Pipe support for user-defined range adaptors
 * , and
 * Windowing range adaptors: and
 * , and
 * Windowing range adaptors: and
 * Windowing range adaptors: and

After the virtual WG21 meeting of 25 July 2022, the following features and defect reports are added where they were approved by straw polls:
 * Made rewriting equality in expressions less of a breaking change.
 * Reverted the deprecation of bitwise assignment to variables.
 * Added the preprocessor directive.
 * Removed non-encodable wide character literals and multicharacter wide character literals.
 * Allowed labels to appear at the end of compound statements.
 * Added escape sequences delimited with curly braces for octal and hexadecimal numbers and universal character names.
 * Allowed functions to never be constant expressions.
 * Simplified some implicit move rules from C++20 and allowed implicit move when returning an rvalue reference.
 * Add a way to specify unicode characters by name. For example,
 * Allowed operator and lambdas to be static.
 * Allowed the  pointer and references of unknown origin to appear in constant expressions.
 * Allowed implementations to define extended floating-point types in addition to the three standard floating-point types. Added the type aliases,  ,  ,  ,   for these extended types accessible through the header  , their corresponding literal suffixes          or           and added overloads to various standard library functions that take floats as arguments.
 * Added the attribute which allows the compiler to assume the provided expression is true to allow optimizations.
 * Made support for UTF-8 source files mandatory, providing a portable encoding for source files.
 * Allowed arrays of and  to be initialized with UTF-8 string literals.
 * Removed the requirement that wchar_t can encode all characters of the extended character set, in effect allowing UTF-16 to be used for wide string literals.
 * Added, a multidimensional array view analogous to.
 * and were added to the standard library.
 * Added the and  functions for printing formatted text to stdout.
 * Provide the named modules and  for importing the standard library.
 * Added support for exclusive mode, analogous to the "x" flag in.
 * Allowed  to handle ranges, tuples, and other containers.
 * Added.
 * Made  use move semantics.
 * Added which implements a coroutine generator that models
 * Added new algorithms:, , and ranges fold algorithms.
 * Made  compatible with other tuple-like objects.
 * Explicit lifetime management for implicit-lifetime types.
 * Made  and integral overloads of   and   -compatible.
 * Adding move-only types support for comparison concepts.
 * Ranges iterators as inputs to non-ranges algorithms.
 * Relaxing range adaptors to allow for move-only types.
 * Relaxing range adaptors to allow for move-only types.

After the hybrid WG21 meeting of 7 November 2022, the following features and defect reports are added where they were approved by straw polls:
 * Allowed to be.
 * Allowed and thread_local variables to appear in  functions if they are usable in constant expressions.
 * consteval propagates upwards, that is, certain existing functions become  functions when those functions can already only be invoked during compile time.
 * Extended the lifetime of temporaries that appear in the for-range-initializer of a range-based loop to cover the entire loop.
 * Reverted the deprecation of (all, not just bitwise) compound assignment to variables.
 * Monadic functions for.
 * Synchronize the output of with the underlying stream if the native Unicode API is used.

After the final hybrid WG21 meeting of 6-11 February 2023, the following features and defect reports are added where they were approved by straw polls: :
 * referencing the Unicode Standard
 * stashing stashing iterators for proper flattening
 * making multi-param constructors of views explicit
 * relaxing ranges just a smidge
 * escaping improvements in std::format
 * improving 's width estimation
 * fill character allowances
 * formatting  and
 * A type trait
 * of  should be a reference type
 * disallowing user specialization of
 * deprecating
 * 's phase completion guarantees
 * deprecating
 * 's phase completion guarantees