C 23
   HOME

TheInfoList



OR:

C++23, formally ISO/IEC 14882:2024, is the current
open standard An open standard is a standard that is openly accessible and usable by anyone. It is also a common prerequisite that open standards use an open license that provides for extensibility. Typically, anybody can participate in their development due to ...
for the C++ programming language that follows
C++20 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
. The final draft of this version is N4950. In February 2020, at the final meeting for
C++20 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
in
Prague Prague ( ; ) is the capital and List of cities and towns in the Czech Republic, largest city of the Czech Republic and the historical capital of Bohemia. Prague, located on the Vltava River, has a population of about 1.4 million, while its P ...
, an overall plan for C++23 was adopted: planned features for C++23 were library support for
coroutine Coroutines are computer program components that allow execution to be suspended and resumed, generalizing subroutines for cooperative multitasking. Coroutines are well-suited for implementing familiar program components such as cooperative task ...
s, 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 The COVID-19 pandemic (also known as the coronavirus pandemic and COVID pandemic), caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), began with an disease outbreak, outbreak of COVID-19 in Wuhan, China, in December ...
, 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 in 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

import std; int main()


Features

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


Language

*explicit this object parameter *if consteval *multidimensional subscript operator *static call and subscript operators and static lambdas *simplifying implicit move *auto(x) and auto *new preprocessor directives: **#elifdef and #elifndef **#warning *extending the lifetime of some temporaries in range-based for loop *new standard attribute assume(expression) *class template argument deduction from inherited constructors *labels at the end of the compound statement *alias declarations in init-statements *literal suffixes for std::size_t and the corresponding signed type *extended floating-point types with literals (conditionally supported) *optional () from nullary lambda expressions *attributes on lambda expressions *constexpr changes: **non-literal variables, labels, and gotos in constexpr functions **allowing static and thread_local variables that are usable in constant expressions in constexpr functions **constexpr function does not need its return type and parameter types to be literal type **it is now possible to write a constexpr function for which no invocation satisfies the requirements of a core constant expression *narrowing contextual conversions to bool in static_assert and if constexpr *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


Library


Standard Library Module Support

*standard library modules std and std.compat


Coroutine Library Support

*synchronous coroutine std::generator for ranges


General Utilities Support

*result type std::expected *monadic operations for std::optional and std::expected *utility function std::to_underlying to get the underlying value of enum *move-only callable wrapper std::move_only_function *std::forward_like *std::invoke_r *std::bind_back *std::byteswap *std::unreachable: a function to mark
unreachable code In computer programming, unreachable code is part of the source code of a program which can never be executed because there exists no control flow path to the code from the rest of the program. Unreachable code is sometimes also called ''dead code ...
*made std::tuple compatible with other ''tuple-like'' objects *std::basic_common_reference specialization for std::reference_wrapper yielding reference types *adding default arguments for std::pair's forwarding constructor


Compile-time Support

*constexpr support for: **std::type_info::operator

** std::bitset ** std::unique_ptr ** for some functions ** for integral overloads of std::to_chars and std::from_chars *metaprogramming utilities: **type traits std::is_scoped_enum, std::is_implicit_lifetime, std::reference_constructs_from_temporary, and std::reference_converts_from_temporary. *adding move-only types support for comparison concepts


Iterators, Ranges, and Algorithm Support

*new range conversion function std::ranges::to *new constrained ranges algorithm: **std::ranges::starts_with **std::ranges::ends_with **std::ranges::contains **std::ranges::contains_subrange **std::ranges::find_last and other variants **rangified versions of iota, shift_left, and shift_right **range fold algorithms * new std::ranges::range_adaptor_closure, a helper for defining user-defined range adaptor closures *new range adaptors: **std::views::zip and other variants **std::views::adjacent and other variants **std::views::join_with **std::views::slide **std::views::chunk **std::views::chunk_by **std::views::as_rvalue **std::views::as_const **std::views::repeat **std::views::stride **std::views::cartesian_product **std::views::enumerate *rectifying constant iterators, sentinels, and ranges, that is, std::ranges::cbegin and other similar utilities returning constant iterators should be fully guaranteed even for shallow-const views (such as std::span) *ranges iterators as inputs to non-ranges algorithms *relaxing range adaptors to allow for move only types *making multi-param constructors of some views explicit


Memory Management Support

*std::out_ptr and std::inout_ptr for C interoperability *std::allocate_at_least and std::allocator::allocate_at_least *explicit lifetime management function std::start_lifetime_as for implicit-lifetime types *disallowing user specialization of std::allocator_traits


String and Text Processing Support

*new member functions and changes in string types: **std::basic_string_view::contains and std::basic_string::contains **disabling construction from nullptr for std::basic_string and std::basic_string_view **explicit range constructor for std::basic_string_view **std::basic_string::resize_and_overwrite **rvalue reference overload of std::basic_string::substr for efficient slicing *formatting ranges, tuples, escaped presentation of characters and strings, std::thread::id, and stacktraces.


Diagnostic Support

*stacktrace library


I/O Support

*formatted output functions std::print and std::println from new header *spanstream library (std::span-based string stream) from new header *a support for exclusive mode in std::fstreams *std::basic_ostream::operator<<(const volatile void*)


Containers Support

*multidimensional-span std::mdspan *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 std::span and std::basic_string_view 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 char8_t *relaxing requirements on wchar_t to match existing practices *allowing some pointers and references of this or unknown origin in constant expressions *introduction of immediate-escalating functions promoted to immediate functions *allowing static_assert(false) in uninstantiated template contexts


Library defect reports

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


Removed features and deprecation

Removed features: *Garbage Collection Support and (strict) Pointer Safety (meaning only ''relaxed pointer safety'' is to be relied upon). This minimal garbage collection support (and pointer safety, needed for it), was added to C++11 but no compilers have ever supported it so the support was removed in C++23. However, that doesn't mean many GC implementations haven't been used, and continue to be used with C++, such as Boehm GC (and it can also just be used for leak detection in leak detection, when in debug mode), and such GC is often implemented in C++, for other languages to use. *Mixed wide-string literal concatenation. *Non-encodable wide character literals and multicharacter wide character literals. Deprecated features: *std::aligned_storage and std::aligned_union *std::numeric_limits::has_denorm 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 operator[]. *C headers (The corresponding <*.h> headers for compatibility with C)


Published as Technical Specifications

* Concurrency TS v2


Compiler support

*
Clang Clang () is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, and the software frameworks OpenMP, OpenCL, RenderScript, CUDA, SYCL, and HIP. It acts as a drop-in replacement for the GNU Compiler ...
progressively added partial C++23 support from 2021 in version 13 through to version 18 in 2024, available through the option -std=c++23. * GCC added partial, experimental C++23 support in 2021 in version 11 through the option -std=c++2b or -std=c++23 It also has an option to enable GNU extensions in addition to the experimental C++23 support, -std=gnu++2b.


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.


November 2020

The following were added after the virtual WG21 meeting of 9 November 2020, where they were approved by straw polls: * Literal suffixes for std:: size_t 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


February 2021

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 . * . * Conditionally borrowed ranges. * .


June 2021

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 . * for , , and . * Iterators pair constructors for (
stack Stack may refer to: Places * Stack Island, an island game reserve in Bass Strait, south-eastern Australia, in Tasmania’s Hunter Island Group * Blue Stack Mountains, in Co. Donegal, Ireland People * Stack (surname) (including a list of people ...
) 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 . * . * Improvements on . * Adding default arguments for 's forwarding constructor.


October 2021

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 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 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."


February 2022

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 cmath and cstdlib * Function to mark
unreachable code In computer programming, unreachable code is part of the source code of a program which can never be executed because there exists no control flow path to the code from the rest of the program. Unreachable code is sometimes also called ''dead code ...
* * A type trait to detect reference binding to temporary * Making * Pipe support for user-defined range adaptors * , and * * Windowing range adaptors: and *


July 2022

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
label A label (as distinct from signage) is a piece of paper, plastic film, cloth, metal, or other material affixed to a container or product. Labels are most often affixed to packaging and containers using an adhesive, or sewing when affix ...
s to appear at the end of compound statements. * Added
escape sequence In computer science, an escape sequence is a combination of characters that has a meaning other than the literal characters contained therein; it is marked by one or more preceding (and possibly terminating) characters. Examples * In C and ma ...
s 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 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
and allowed implicit move when returning an rvalue reference. * Add a way to specify
unicode Unicode or ''The Unicode Standard'' or TUS is a character encoding standard maintained by the Unicode Consortium designed to support the use of text in all of the world's writing systems that can be digitized. Version 16.0 defines 154,998 Char ...
characters by name. For example, * Allowed and lambdas to be . * Allowed the this pointer and
references A reference is a relationship between Object (philosophy), objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. ...
of unknown origin to appear in constant expressions. * Allowed implementations to define extended
floating-point In computing, floating-point arithmetic (FP) is arithmetic on subsets of real numbers formed by a ''significand'' (a Sign (mathematics), signed sequence of a fixed number of digits in some Radix, base) multiplied by an integer power of that ba ...
types in addition to the three standard floating-point types. Added the type aliases std::float16_t, std::float32_t, std::float64_t, std::float128_t, std::bfloat16_t for these extended types accessible through the header , their corresponding literal suffixes f16 f32 f64 f128 bf16or F16 F32 F64 F128 BF16 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 UTF-8 is a character encoding standard used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode Transformation Format 8-bit''. Almost every webpage is transmitted as UTF-8. UTF-8 supports all 1,112,0 ...
source files mandatory, providing a portable encoding for source files. * Allowed arrays of and to be initialized with UTF-8
string literal string literal or anonymous string is a literal for a string value in the source code of a computer program. Modern programming languages commonly use a quoted sequence of characters, formally "bracketed delimiters", as in x = "foo", where , "foo ...
s. * Removed the requirement that can encode all characters of the extended character set, in effect allowing UTF-16 to be used for wide string literals. * Added std::mdspan, a multidimensional array view analogous to std::span. * 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 fstreams, analogous to the "x" flag in fopen. * Allowed std::format to handle ranges, tuples, and other containers. * Added std::forward_like. * Made std::string::substr use move semantics. * Added which implements a coroutine generator that models * , , , , . * Added new algorithms: , , and ranges fold algorithms. * Made std::tuple compatible with other ''tuple-like'' objects. * Explicit lifetime management for implicit-lifetime types. * Made std::bitset and integral overloads of std::to_chars and std::from_chars -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.


November 2022

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 variables to appear in functions if they are usable in constant expressions. * 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.


February 2023

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. * views::enumerate * making multi-param constructors of views explicit * relaxing ranges just a smidge * escaping improvements in std::format * improving std::format's width estimation * std::format fill character allowances * formatting thread::id and stacktrace * A type trait std::is_implicit_lifetime * std::common_reference_t of std::reference_wrapper should be a reference type * disallowing user specialization of std::allocator_traits * std::pmr::generator * deprecating std::numeric_limits::has_denorm * std::barrier's phase completion guarantees


External links


Compiler support for C++23 features


References

{{C++ programming language C++ C++ programming language family Algol programming language family High-level programming languages Statically typed programming languages