| C++ language revisions |
|---|
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++.
Changes accepted into C++23 include the following language and standard-library features. A feature-by-feature summary is also maintained by cppreference.
this object parameterif constevala[i, j, k] = x; instead of a[i][j][k] = x;operator() and operator[] functions, and static lambdasauto(x) and auto{x}#elifdef and #elifndef#warning[[assume(expression)]]z for the corresponding signed integer type and uz or zu for std::size_t (for example, 0z and 15zu)() from nullary lambda expressionsconstexpr changes:
gotos in constexpr functionsstatic and thread_local variables that are usable in constant expressions in constexpr functionsconstexpr functions, including permitting a function to be declared constexpr even if no invocation satisfies the requirements for a core constant expressionbool in static_assert and if constexprstd and std.compatstd::generator<Ref, V, Allocator> for rangesstd::expected<T, E>std::optional<T> and std::expectedstd::to_underlying to get the underlying value of enumstd::move_only_functionstd::forward_likestd::invoke_rstd::bind_backstd::byteswapstd::unreachable: a function to mark unreachable codestd::tuple compatible with other tuple-like objectsstd::basic_common_reference specialization for std::reference_wrapper yielding reference typesstd::pair<T, U>'s forwarding constructorconstexpr support for:
std::type_info::operator==std::bitsetstd::unique_ptr<cmath> functionsstd::to_chars and std::from_charsstd::is_scoped_enum, std::is_implicit_lifetime, std::reference_constructs_from_temporary, and std::reference_converts_from_temporary.std::ranges::tostd::ranges::starts_withstd::ranges::ends_withstd::ranges::containsstd::ranges::contains_subrangestd::ranges::find_last and other variantsiota, shift_left, and shift_rightstd::ranges::range_adaptor_closure, a helper for defining user-defined range adaptor closuresstd::views::zip family, including zip_transformstd::views::adjacent family, including adjacent_transformstd::views::join_withstd::views::slidestd::views::chunkstd::views::chunk_bystd::views::as_rvaluestd::views::as_conststd::views::repeatstd::views::stridestd::views::cartesian_productstd::views::enumeratestd::ranges::cbegin and other similar utilities returning constant iterators should be fully guaranteed even for shallow-const views (such as std::span)explicitstd::out_ptr and std::inout_ptr for C interoperabilitystd::allocator_traits<Alloc>::allocate_at_least and std::allocator<T>::allocate_at_leaststd::start_lifetime_as for implicit-lifetime typesstd::allocator_traitsstd::basic_string_view::contains and std::basic_string::containsnullptr for std::basic_string and std::basic_string_viewstd::basic_string_viewstd::basic_string::resize_and_overwritestd::basic_string::substr, which can reuse storage when called on an rvalue stringstd::thread::id and stacktraces.<stacktrace> and type std::stacktracestd::print and std::println from new header <print>std::span-based string stream) from new header <spanstream>std::fstreamsstd::basic_ostream::operator<<(const volatile void* p)std::mdspanstd::flat_map, std::flat_multimap, std::flat_set and std::flat_multisetstd::span and std::basic_string_view to be trivially copyable<stdatomic.h>char8_t and UTF-8 string literalswchar_t to match existing practicesstatic_assert(false) in uninstantiated template contextsstd::counted_iteratorstd::ranges::join_viewstd::ranges::split_view to std::ranges::lazy_split_view and new split_viewstd::default_initializable constraint from concept std::ranges::viewstd::ranges::owning_viewstd::ranges::istream_viewstd::basic_format_stringstd::format_tostd::formatconstexpr std::variant and std::optionalstd::variant in std::visitRemoved features:
Deprecated features:
std::aligned_storage and std::aligned_unionstd::float_denorm_style, std::numeric_limits<T>::has_denorm and std::numeric_limits<T>::has_denorm_lossReverted deprecations:
operator[] so that it can take multiple parameters..h suffixes are no longer deprecated, although their use is discouraged in C++-only code where C interoperability is not needed.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.
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.
-std=c++23 mode, but its status page lists C++23 support as partial.-std=c++23 mode, as well as -std=gnu++23 for GNU extensions. Its status page describes its C++23 implementation as experimental and lists support feature by feature.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.
The WG21 minutes record positive straw polls on the following items at the virtual meeting of 9 November 2020:
std::size_t and the corresponding signed typecontains for std::basic_string and std::basic_string_view, to check whether or not the string contains a given substring or character<stacktrace>)std::is_scoped_enum<stdatomic.h>, for interoperability with C atomicsThe WG21 minutes record positive straw polls on the following items at the virtual meeting of 22 February 2021:
() from lambda expressions.counted_iterator.time_point::clock.std::visit for classes that are derived from std::variant.std::to_underlying.The WG21 minutes record positive straw polls on the following feature proposals and defect resolutions at the virtual meeting in June 2021:
if consteval).bool.std::span-based string-stream (<spanstream>).std::out_ptr() and std::inout_ptr().constexpr for std::optional, std::variant, and std::type_info::operator==.std::stack (stack) and std::queue (queue).starts_with and ends_with for arbitrary ranges.split_view to lazy_split_view and new split_view.join_view.default_initializable constraint from concept view.std::basic_string_view.std::basic_string and std::basic_string_view construction from nullptr.std::invoke_r.std::format.std::pair's forwarding constructor.The WG21 minutes record positive straw polls on the following feature proposals and defect resolutions at the virtual meeting in October 2021:
constexpr functions, but still ill-formed to evaluate them at compile-time.this object parameter.#elifdef and #elifndef. Both directives were added to C23 (C language update) and GCC 12.arr[1, 2]).auto(x) or auto{x}.std::generator-like types.std::pmr::stacktrace alias for std::basic_stacktrace<std::pmr::polymorphic_allocator<std::stacktrace_entry>>.std::ranges::istream_view with alias templates std::ranges::istream_view, std::ranges::wistream_view, and customization point object std::views::istream.zip range adaptor family:
zip_viewzip_transform_viewadjacent_view (and std::views::pairwise being equivalent to std::views::adjacent<2>)adjacent_transform_view (and std::views::pairwise_transform being equivalent to std::views::adjacent_transform<2>)std::move_only_function.std::optional.std::basic_string::resize_and_overwrite.volatile pointers (volatile T*).std::byteswap.std::span and std::basic_string_view is trivially copyable.noexcept specifications to std::exchange.The WG21 minutes record positive straw polls on the following proposals at the virtual meeting of 7 February 2022:
std::expectedconstexpr for cmath and cstdlibranges::tostd::unique_ptr constexprranges::iota, ranges::shift_left and ranges::shift_rightviews::join_withviews::chunk and views::slideviews::chunk_byThe WG21 minutes record positive straw polls on the following proposals and defect resolutions at the virtual meeting of 25 July 2022:
volatile variables.#warning preprocessor directive.constexpr functions to never be constant expressions.U'\N{LATIN CAPITAL LETTER A WITH MACRON}' is equivalent to U'\u0100'.operator() and lambdas to be static.<stdfloat> provides aliases such as std::float16_t, std::float32_t, std::float64_t, std::float128_t and std::bfloat16_t, with corresponding literal suffixes such as f16, f32, f64, f128 and bf16 (and uppercase forms), as well as relevant standard-library overloads.[[assume(expression)]] attribute, which lets an implementation assume that the expression is true for optimization purposes; it is not a run-time assertion.char and unsigned char to be initialized from UTF-8 string literals, as a compatibility measure for char8_t.wchar_t to represent all members of the extended character set, accommodating implementations in which wide characters use UTF-16.std::mdspan, a multidimensional array view analogous to std::span.std::flat_map, std::flat_multimap, std::flat_set and std::flat_multiset were added to the standard library.std::print and std::println for formatted output, including output to standard output.std and std.compat for importing the standard library.fstreams, analogous to the "x" flag in fopen.std::format to handle ranges, tuples, and other containers.std::forward_like.std::basic_string::substr() && overload, allowing substring extraction from an rvalue string to reuse its storage where applicable.std::generator, a coroutine generator that models std::ranges::input_range.views::cartesian_product, views::repeat, views::stride, views::as_const, views::as_rvalue.ranges::find_last, ranges::contains, and ranges fold algorithms.std::tuple compatible with other tuple-like objects.std::bitset and integral overloads of std::to_chars and std::from_chars constexpr-compatible.The WG21 minutes record positive straw polls on the following proposals and defect resolutions at the hybrid meeting of 7 November 2022:
operator[] to be static.static and thread_local variables to appear in constexpr functions if they are usable in constant expressions.consteval propagates upwards, that is, certain existing constexpr functions become consteval functions when those functions can already only be invoked during compile time.for loop to cover the entire loop.volatile variables.std::expected.std::print with the underlying stream if the native Unicode API is used.The WG21 minutes record positive straw polls on the following proposals and defect resolutions at the final hybrid meeting of 6–11 February 2023:
std::views::enumerate, a range adaptor that yields elements together with their indices.std::format.std::format's width estimationstd::formatstd::thread::id and stacktracesstd::is_implicit_lifetimestd::common_reference_t involving std::reference_wrapper can be a reference typestd::allocator_traitsstd::pmr::generatorstd::float_denorm_style, std::numeric_limits<T>::has_denorm and std::numeric_limits<T>::has_denorm_lossstd::barrier's phase-completion guarantees, including changes to which thread may execute the completion step.