C++23
2023 edition of the C++ programming language standard
C++23, formally ISO/IEC 14882:2024 (the seventh edition), is the version of the C++ programming language standard published in October 2024. It follows C++20. N4950 is the final WG21 working draft for C++23, and WG21 completed the technical work on the revision at its meeting in February 2023. The successor revision, commonly referred to as C++26, is being developed as ISO/IEC DIS 14882, which ISO identifies as the next version intended to replace ISO/IEC 14882:2024.
Compiler support for C++23 varies by compiler version, language feature, and standard-library component. Clang lists C++23 mode as partial, while GCC describes its implementation as experimental; Microsoft publishes feature-by-feature conformance information for Visual C++.
Features
Changes accepted into C++23 include the following language and standard-library features. A feature-by-feature summary is also maintained by cppreference.
Language
- explicit
thisobject parameter if consteval- multidimensional subscript operator; this operator may be defined with any number of parameters (or even be variadic), allowing for defining
a[i, j, k] = x;instead ofa[i][j][k] = x; - static
operator()andoperator[]functions, and static lambdas - simplifying implicit move
auto(x)andauto{x}- new preprocessor directives:
#elifdefand#elifndef#warning
- extending the lifetime of temporaries within the range-initializer of a range-based for loop to the lifetime of the loop
- new standard attribute
[[assume(expression)]] - class template argument deduction from inherited constructors
- labels at the end of compound statements
- alias declarations in init-statements
- integer-literal suffixes
zfor the corresponding signed integer type anduzorzuforstd::size_t(for example,0zand15zu) - extended floating-point types with literals (conditionally supported)
- optional
()from nullary lambda expressions - attributes on lambda expressions
constexprchanges:- non-literal variables, labels, and
gotos inconstexprfunctions - allowing
staticandthread_localvariables that are usable in constant expressions inconstexprfunctions - relaxing restrictions on
constexprfunctions, including permitting a function to be declaredconstexpreven if no invocation satisfies the requirements for a core constant expression
- non-literal variables, labels, and
- narrowing contextual conversions to
boolinstatic_assertandif constexpr - trimming whitespaces before line splicing
- requiring declaration-order layout for non-static data members, subject to the rules for potentially overlapping subobjects
- 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
stdandstd.compat
Coroutine Library Support
- synchronous coroutine generator
std::generator<Ref, V, Allocator>for ranges
General Utilities Support
- result type
std::expected<T, E> - monadic operations for
std::optional<T>andstd::expected - utility function
std::to_underlyingto get the underlying value of enum - move-only callable wrapper
std::move_only_function std::forward_likestd::invoke_rstd::bind_backstd::byteswapstd::unreachable: a function to mark unreachable code- made
std::tuplecompatible with other tuple-like objects std::basic_common_referencespecialization forstd::reference_wrapperyielding reference types- adding default template arguments for
std::pair<T, U>'s forwarding constructor
Compile-time Support
constexprsupport for:std::type_info::operator==std::bitsetstd::unique_ptr- for some
<cmath>functions - for integral overloads of
std::to_charsandstd::from_chars
- metaprogramming utilities:
- type traits
std::is_scoped_enum,std::is_implicit_lifetime,std::reference_constructs_from_temporary, andstd::reference_converts_from_temporary.
- type traits
- adding move-only types support for comparison concepts
Iterators, Ranges, and Algorithm Support
- range conversion utility
std::ranges::to - new constrained ranges algorithms:
std::ranges::starts_withstd::ranges::ends_withstd::ranges::containsstd::ranges::contains_subrangestd::ranges::find_lastand other variants- rangified versions of
iota,shift_left, andshift_right - range fold algorithms
- new
std::ranges::range_adaptor_closure, a helper for defining user-defined range adaptor closures - new range adaptors:
- the
std::views::zipfamily, includingzip_transform - the
std::views::adjacentfamily, includingadjacent_transform std::views::join_withstd::views::slidestd::views::chunkstd::views::chunk_bystd::views::as_rvaluestd::views::as_conststd::views::repeatstd::views::stridestd::views::cartesian_productstd::views::enumerate
- the
- rectifying constant iterators, sentinels, and ranges, that is,
std::ranges::cbeginand other similar utilities returning constant iterators should be fully guaranteed even for shallow-const views (such asstd::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_ptrandstd::inout_ptrfor C interoperabilitystd::allocator_traits<Alloc>::allocate_at_leastandstd::allocator<T>::allocate_at_least- explicit lifetime management function
std::start_lifetime_asfor 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::containsandstd::basic_string::contains- disabling construction from
nullptrforstd::basic_stringandstd::basic_string_view - explicit range constructor for
std::basic_string_view std::basic_string::resize_and_overwrite- rvalue-qualified overload of
std::basic_string::substr, which can reuse storage when called on an rvalue string
- formatting ranges and tuples, escaped presentation of characters and strings, and formatting of
std::thread::idand stacktraces.
Diagnostic Support
- stacktrace library, header
<stacktrace>and typestd::stacktrace
I/O Support
- formatted output functions
std::printandstd::printlnfrom new header<print> - spanstream library (
std::span-based string stream) from new header<spanstream> - support for exclusive mode in
std::fstreams std::basic_ostream::operator<<(const volatile void* p)
Containers Support
- multidimensional-span
std::mdspan - constructability and assignability of containers from other compatible ranges
- flat associative-container adaptors:
std::flat_map,std::flat_multimap,std::flat_setandstd::flat_multiset - 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::spanandstd::basic_string_viewto be trivially copyable
C-Compatibility Support
- new header
<stdatomic.h>
Language defect reports
- C++ identifier syntax using Unicode Standard Annex 31
- allowing duplicate attributes
- changing scope of lambda trailing return type
- making the effects of rewritten comparison candidates less disruptive to existing code
- undeprecating volatile compound assignments
- fixing some compatibility and portability issues involving
char8_tand UTF-8 string literals - relaxing requirements on
wchar_tto match existing practices - relaxing restrictions on using certain pointers and references of unknown origin in constant expressions
- introducing immediate-escalating functions, which can become immediate functions under specified conditions
- 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_viewtostd::ranges::lazy_split_viewand newsplit_view - removed
std::default_initializableconstraint from conceptstd::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
constexprstd::variantandstd::optional - supporting types derived from
std::variantinstd::visit
Removed features and deprecation
Removed features:
- Removed the language and standard-library provisions for garbage-collection support and reachability-based leak detection, including the strict pointer-safety interface. This removes those facilities from the C++ standard but does not prevent C++ programs from using separate garbage-collection libraries.
- Mixed wide-string literal concatenation.
- Non-encodable wide character literals and multicharacter wide character literals.
Deprecated features:
std::aligned_storageandstd::aligned_unionstd::float_denorm_style,std::numeric_limits<T>::has_denormandstd::numeric_limits<T>::has_denorm_loss
Reverted deprecations:
- The use of the comma operator in subscript expressions is no longer deprecated. C++23 also changes the rules for overloaded
operator[]so that it can take multiple parameters. - The corresponding C-compatibility headers with
.hsuffixes are no longer deprecated, although their use is discouraged in C++-only code where C interoperability is not needed.
Related technical specification
The Concurrency Technical Specification, second edition, was published separately as ISO/IEC TS 9922:2024. It specifies an interface through which C++ programs can invoke algorithms with concurrent execution; it is a separate technical specification, not part of ISO/IEC 14882:2024.
Compiler support
Support for C++23 varies by compiler version and by language and standard-library feature; enabling a C++23 language mode does not imply complete implementation of the standard.
- Clang provides the
-std=c++23mode, but its status page lists C++23 support as partial. - GCC provides the
-std=c++23mode, as well as-std=gnu++23for GNU extensions. Its status page describes its C++23 implementation as experimental and lists support feature by feature. - Microsoft Visual C++ documents support for C++23 language and standard-library features by Visual Studio release.
- cppreference maintains a comparative table of C++23 language and standard-library feature support across compilers and standard-library implementations.
History
In February 2020, at the final meeting for C++20 in Prague, WG21 discussed an early overall plan for C++23: The roadmap proposed library support for coroutines, a modular standard library, executors, and networking. This was an early plan rather than a guarantee that all proposals would be included; executors and networking were not included in the final C++23 standard.
The planned in-person WG21 meeting in Varna in June 2020 was cancelled because of the COVID-19 pandemic, and the committee shifted to remote meetings and work. The planned in-person meetings in New York and Kona, Hawaii were also replaced by virtual meetings. WG21 meetings remained virtual until November 2022; the November 2022 and February 2023 meetings were hybrid. The standard was technically finalized by WG21 at the hybrid meeting in Issaquah in February 2023.
WG21 used straw polls during virtual meetings to gauge consensus on proposed changes. The meeting-by-meeting summaries below identify proposals or defect resolutions that received positive straw polls; a straw poll was not itself final ISO publication approval.
November 2020
The WG21 minutes record positive straw polls on the following items at the virtual meeting of 9 November 2020:
- Literal suffixes for
std::size_tand the corresponding signed type - A member function
containsforstd::basic_stringandstd::basic_string_view, to check whether or not the string contains a given substring or character - A stacktrace library (
<stacktrace>) - A type trait
std::is_scoped_enum - The header
<stdatomic.h>, for interoperability with C atomics
February 2021
The WG21 minutes record positive straw polls on the following items at the virtual meeting of 22 February 2021:
- Removing unnecessary empty parameter list
()from lambda expressions. - Repairing input range adaptors and
counted_iterator. - Relax the requirements for
time_point::clock. std::visitfor classes that are derived fromstd::variant.- Clarified the requirements for lockable objects used by the standard threading library.
- Conditionally borrowed ranges.
std::to_underlying.
June 2021
The WG21 minutes record positive straw polls on the following feature proposals and defect resolutions at the virtual meeting in June 2021:
- Consteval if (
if consteval). - Narrowing contextual conversions to
bool. - Allowing duplicate attributes.
std::span-based string-stream (<spanstream>).std::out_ptr()andstd::inout_ptr().constexprforstd::optional,std::variant, andstd::type_info::operator==.- Iterators pair constructors for
std::stack(stack) andstd::queue(queue). - Selected changes to the ranges library:
- Generalized
starts_withandends_withfor arbitrary ranges. - Renamed
split_viewtolazy_split_viewand newsplit_view. - Relaxing the constraint on
join_view. - Removing
default_initializableconstraint from conceptview. - Range constructor for
std::basic_string_view.
- Generalized
- Prohibiting
std::basic_stringandstd::basic_string_viewconstruction fromnullptr. std::invoke_r.- Improvements on
std::format. - Adding default template arguments for
std::pair's forwarding constructor.
October 2021
The WG21 minutes record positive straw polls on the following feature proposals and defect resolutions at the virtual meeting in October 2021:
- Non-literal variables, labels, and gotos in
constexprfunctions, but still ill-formed to evaluate them at compile-time. - Explicit
thisobject parameter. - Changes on character sets and encodings.
- New preprocessing directives:
#elifdefand#elifndef. Both directives were added to C23 (C language update) and GCC 12. - Allowing alias declarations in init-statement.
- Overloading multidimensional subscript operator (e.g.
arr[1, 2]). - Decay copy in language:
auto(x)orauto{x}. - Changes in text formatting library:
- Fixing locale handling in chrono formatters.
- Use of forwarding references in format arguments to allow
std::generator-like types.
- Added the
std::pmr::stacktracealias forstd::basic_stacktrace<std::pmr::polymorphic_allocator<std::stacktrace_entry>>. - Changes in ranges library:
- Refined definition of a view.
- Replacing function template
std::ranges::istream_viewwith alias templatesstd::ranges::istream_view,std::ranges::wistream_view, and customization point objectstd::views::istream. ziprange adaptor family:zip_viewzip_transform_viewadjacent_view(andstd::views::pairwisebeing equivalent tostd::views::adjacent<2>)adjacent_transform_view(andstd::views::pairwise_transformbeing equivalent tostd::views::adjacent_transform<2>)
std::move_only_function.- Monadic operations for
std::optional. - Member function template
std::basic_string::resize_and_overwrite. - Printing
volatilepointers (volatile T*). std::byteswap.- Heterogeneous erasure overloads for associative containers.
- Every specialization of
std::spanandstd::basic_string_viewis trivially copyable. - Adding conditional
noexceptspecifications tostd::exchange. - Revamped specification and use of integer-class types.
- Clarified that the C-compatibility headers remain supported and are no longer deprecated, while their use is discouraged in C++-only code that does not need C interoperability.
February 2022
The WG21 minutes record positive straw polls on the following proposals at the virtual meeting of 7 February 2022:
- Allowed attributes on the function call operator of a lambda
std::expectedconstexprforcmathandcstdlib- Function to mark unreachable code
ranges::to- A type trait to detect reference binding to temporary
- Making
std::unique_ptrconstexpr - Pipe support for user-defined range adaptors
ranges::iota,ranges::shift_leftandranges::shift_rightviews::join_with- Windowing range adaptors:
views::chunkandviews::slide views::chunk_by
July 2022
The WG21 minutes record positive straw polls on the following proposals and defect resolutions at the virtual meeting of 25 July 2022:
- Made rewriting equality in expressions less of a breaking change.
- Reverted the deprecation of bitwise assignment to
volatilevariables. - Added the
#warningpreprocessor 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
constexprfunctions to never be constant expressions. - Simplified some implicit move rules from C++20 and allowed implicit move when returning an rvalue reference.
- Added named universal character escapes, which allow Unicode characters to be referred to by name. For example,
U'\N{LATIN CAPITAL LETTER A WITH MACRON}'is equivalent toU'\u0100'. - Allowed
operator()and lambdas to bestatic. - Relaxed restrictions on using pointers and references of unknown origin in constant expressions.
- Allowed implementations to support extended floating-point types in addition to the three standard floating-point types. Where supported, the optional header
<stdfloat>provides aliases such asstd::float16_t,std::float32_t,std::float64_t,std::float128_tandstd::bfloat16_t, with corresponding literal suffixes such asf16,f32,f64,f128andbf16(and uppercase forms), as well as relevant standard-library overloads. - Added the
[[assume(expression)]]attribute, which lets an implementation assume that the expression is true for optimization purposes; it is not a run-time assertion. - Required implementations to support UTF-8 encoded source files as a portable source encoding.
- Allowed arrays of
charandunsigned charto be initialized from UTF-8 string literals, as a compatibility measure forchar8_t. - Relaxed the requirement for
wchar_tto represent all members of the extended character set, accommodating implementations in which wide characters use UTF-16. - Added
std::mdspan, a multidimensional array view analogous tostd::span. - The flat associative-container adaptors
std::flat_map,std::flat_multimap,std::flat_setandstd::flat_multisetwere added to the standard library. - Added
std::printandstd::printlnfor formatted output, including output to standard output. - Added the named modules
stdandstd.compatfor importing the standard library. - Added support for exclusive mode
fstreams, analogous to the "x" flag infopen. - Allowed
std::formatto handle ranges, tuples, and other containers. - Added
std::forward_like. - Added an rvalue-qualified
std::basic_string::substr() &&overload, allowing substring extraction from an rvalue string to reuse its storage where applicable. - Added
std::generator, a coroutine generator that modelsstd::ranges::input_range. views::cartesian_product,views::repeat,views::stride,views::as_const,views::as_rvalue.- Added new algorithms:
ranges::find_last,ranges::contains, and ranges fold algorithms. - Made
std::tuplecompatible with other tuple-like objects. - Added explicit lifetime-management functions for implicit-lifetime types.
- Made
std::bitsetand integral overloads ofstd::to_charsandstd::from_charsconstexpr-compatible. - Adding move-only types support for comparison concepts.
- Allowing ranges iterators to be used as inputs to non-ranges algorithms.
- Relaxing range adaptors to allow for move-only types.
November 2022
The WG21 minutes record positive straw polls on the following proposals and defect resolutions at the hybrid meeting of 7 November 2022:
- Allowed
operator[]to bestatic. - Allowed
staticandthread_localvariables to appear inconstexprfunctions if they are usable in constant expressions. constevalpropagates upwards, that is, certain existingconstexprfunctions becomeconstevalfunctions 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
forloop to cover the entire loop. - Reverted the deprecation of (all, not just bitwise) compound assignment to
volatilevariables. - Monadic operations for
std::expected. - Synchronize the output of
std::printwith the underlying stream if the native Unicode API is used.
February 2023
The WG21 minutes record positive straw polls on the following proposals and defect resolutions at the final hybrid meeting of 6–11 February 2023:
- Referencing the Unicode Standard.
- Adjusted the ranges library to account for stashing iterators when flattening nested ranges.
std::views::enumerate, a range adaptor that yields elements together with their indices.- making multi-parameter constructors of some views explicit
- relaxing constraints on some range adaptors
- escaping improvements in
std::format. - improving
std::format's width estimation - changing fill-character allowances in
std::format - formatting
std::thread::idand stacktraces - a type trait
std::is_implicit_lifetime - ensuring
std::common_reference_tinvolvingstd::reference_wrappercan be a reference type - disallowing user specialization of
std::allocator_traits - the polymorphic-allocator alias
std::pmr::generator - deprecating
std::float_denorm_style,std::numeric_limits<T>::has_denormandstd::numeric_limits<T>::has_denorm_loss std::barrier's phase-completion guarantees, including changes to which thread may execute the completion step.
Adapted from the Wikipedia article, CC BY-SA 4.0. Continue on Wikipedia
Go deeper
Ideas this article links to.