This article has multiple issues. Please help
improve it or discuss these issues on the
talk page. (
Learn how and when to remove these template messages)
|
C++ language revisions |
---|
C++23 is the informal name for the version of the ISO/ IEC 14882 standard for the C++ programming language that followed C++20. The final draft of this version is N4950. [1] [2]
In February 2020, at the final meeting for C++20 in Prague, an overall plan for C++23 was adopted: [3] [4] planned features for C++23 were 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, [5] [6] as was the November 2020 meeting in New York [7] [6] and the February 2021 meeting in Kona, Hawaii. [7] All meetings until November 2022 were virtual while the November 2022 meeting until the final meeting on February 2023 was hybrid. [7] The standard was technically finalized by WG21 at the hybrid meeting in Issaquah in February 2023. [8]
After many library changes applied to the working draft, the new "Hello, world" program will be:
import std;
int main()
{
std::println("Hello, world!");
}
Changes that have been accepted into C++23 include:
this
object parameter
[9]if consteval
[10]auto(x)
and auto{x}
[15][[assume(expression)]]
[19]std::size_t
and the corresponding signed type
[23]()
from nullary
lambda expressions
[25]constexpr
changes:
goto
s in constexpr
functions
[27]static
and thread_local
variables that are usable in constant expressions in constexpr
functions
[28]constexpr
function does not need its return type and parameter types to be literal typeconstexpr
function for which no invocation satisfies the requirements of a core constant expression
[29]bool
in static_assert
and if constexpr
[30]std
and std.compat
[38]std::generator
for ranges
[39]std::expected
[40]std::optional
[41] and std::expected
[42]std::to_underlying
to get the underlying value of enum
[43]std::move_only_function
[44]std::forward_like
[45]std::invoke_r
[46]std::bind_back
[47]std::byteswap
[48]std::unreachable
: a function to mark
unreachable code
[49]std::tuple
compatible with other tuple-like objects
[50]std::basic_common_reference
specialization for std::reference_wrapper
yielding reference types
[51]std::pair
's forwarding constructor
[52]constexpr
support for:
std::ranges::to
[62]std::ranges::range_adaptor_closure
, a helper for defining user-defined range adaptor closures
[47]std::views::zip
and other variantsstd::views::adjacent
and other variants
[68]std::views::join_with
[69]std::views::slide
std::views::chunk
[70]std::views::chunk_by
[71]std::views::as_rvalue
[72]std::views::as_const
[73]std::views::repeat
[74]std::views::stride
[75]std::views::cartesian_product
[76]std::views::enumerate
[77]std::ranges::cbegin
and other similar utilities returning constant iterators should be fully guaranteed even for shallow-const views (such as std::span
)
[73]explicit
[80]std::out_ptr
and std::inout_ptr
for C interoperability
[81]std::allocate_at_least
and std::allocator::allocate_at_least
[82]std::start_lifetime_as
for implicit-lifetime types
[83]std::allocator_traits
[84]std::basic_string_view::contains
and std::basic_string::contains
[85]nullptr
for std::basic_string
and std::basic_string_view
[86]std::basic_string_view
[87]std::basic_string::resize_and_overwrite
[88]std::basic_string::substr
for efficient slicing
[89]std::thread::id
, and stacktraces.
[90]
[91]
[92]std::print
and std::println
from new header <print>
[94]std::span
-based string stream) from new header <spanstream>
[95]std::fstream
s
[96]std::basic_ostream::operator<<(const volatile void*)
[97]std::mdspan
[98]
[99]
[100]
[101]std::span
and std::basic_string_view
to be trivially copyable
[107]<stdatomic.h>
[108]char8_t
[115]wchar_t
to match existing practices
[116]this
or unknown origin in constant expressions
[117]static_assert(false)
in uninstantiated template contextsstd::counted_iterator
[120]std::ranges::join_view
[121]std::ranges::split_view
to std::ranges::lazy_split_view
and new split_view
[122]std::default_initializable
constraint from concept std::ranges::view
[123]std::ranges::owning_view
[124]std::ranges::istream_view
[125]std::basic_format_string
[126]std::format_to
[127]std::format
[130]constexpr
std::variant
and std::optional
[132]std::variant
in std::visit
[133]Removed features:
Deprecated features:
Reverted deprecated features:
operator[]
.<*.h>
headers for compatibility with C)-std=c++23
.
[140]-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
.
[141]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: [142]
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>
), based on
Boost.Stacktracestd::is_scoped_enum
<stdatomic.h>
, for interoperability with
C atomicsAfter the virtual WG21 meeting of 22 February 2021, following features are added where they were approved by straw polls: [143]
()
from
lambda expressions.counted_iterator
.time_point::clock
.
[144]std::visit
for classes that are derived from std::variant
.std::to_underlying
.After the summer 2021 ISO C++ standards plenary virtual meeting of June 2021, new features and defect reports were approved by straw polls: [146]
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.After the autumn 2021 ISO C++ standards plenary virtual meeting of October 2021, new features and defect reports were approved by straw polls: [147]
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.
[148]arr1, 2
).auto(x)
or auto{x}
.std::generator
-like types.std::pmr::stacktrace
which is equivalent to std::basic_stacktrace<std::pmr::polymorphic_allocator>
.
[149]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_view
zip_transform_view
adjacent_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
.
[150]After the virtual WG21 meeting of 7 February 2022, the following features are added where they were approved by straw polls: [153]
std::expected
constexpr
for cmath
and cstdlib
ranges::to
std::unique_ptr
constexpr
ranges::iota
, ranges::shift_left
and ranges::shift_right
views::join_with
views::chunk
and views::slide
views::chunk_by
After the virtual WG21 meeting of 25 July 2022, the following features and defect reports are added where they were approved by straw polls: [154]
volatile
variables.#warning
preprocessor directive.constexpr
functions to never be constant expressions.U'\N{LATIN CAPITAL LETTER A WITH MACRON}' // Equivalent to U'\u0100'
operator()
and lambdas to be
static
.
this
pointer and
references of unknown origin to appear in constant expressions.std::float16_t
, std::float32_t
, std::float64_t
, std::float128_t
,
std::bfloat16_t
for these extended types accessible through the header <stdfloat>
, their corresponding literal suffixes f16
f32
f64
f128
bf16
or F16
F32
F64
F128
BF16
and added overloads to various standard library functions that take floats as arguments.[[assume(expression)]]
attribute which allows the compiler to assume the provided expression is true to allow optimizations.char
and unsigned char
to be initialized with UTF-8
string literals.wchar_t
can encode all characters of the extended character set, in effect allowing UTF-16 to be used for wide string literals.std::mdspan
, a multidimensional array view analogous to std::span
.flat_map
and flat_set
were added to the standard library.std::print
and std::println
functions for printing formatted text to
stdout.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::string::substr
use
move semantics.std::generator
which implements 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.After the hybrid WG21 meeting of 7 November 2022, the following features and defect reports are added where they were approved by straw polls: [155]
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.
[156]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: [157]
views::enumerate
std::format
std::format
's width estimationstd::format
fill character allowancesthread::id
and stacktrace
std::is_implicit_lifetime
std::common_reference_t
of std::reference_wrapper
should be a reference typestd::allocator_traits
std::pmr::generator
std::numeric_limits::has_denorm
std::barrier
's phase completion guaranteesstatic constexpr
variables in constexpr
functions". 2022-11-07.
std::expected
".
mdspan
: rename pointer
and contiguous
". 15 June 2022.
empty
to mdspan
".
char8_t
Compatibility and Portability Fix". 2022-06-17.
wchar_t
to match existing practices" (PDF). 2022-07-15.
consteval
needs to propagate up". 2022-11-11.
This article has multiple issues. Please help
improve it or discuss these issues on the
talk page. (
Learn how and when to remove these template messages)
|
C++ language revisions |
---|
C++23 is the informal name for the version of the ISO/ IEC 14882 standard for the C++ programming language that followed C++20. The final draft of this version is N4950. [1] [2]
In February 2020, at the final meeting for C++20 in Prague, an overall plan for C++23 was adopted: [3] [4] planned features for C++23 were 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, [5] [6] as was the November 2020 meeting in New York [7] [6] and the February 2021 meeting in Kona, Hawaii. [7] All meetings until November 2022 were virtual while the November 2022 meeting until the final meeting on February 2023 was hybrid. [7] The standard was technically finalized by WG21 at the hybrid meeting in Issaquah in February 2023. [8]
After many library changes applied to the working draft, the new "Hello, world" program will be:
import std;
int main()
{
std::println("Hello, world!");
}
Changes that have been accepted into C++23 include:
this
object parameter
[9]if consteval
[10]auto(x)
and auto{x}
[15][[assume(expression)]]
[19]std::size_t
and the corresponding signed type
[23]()
from nullary
lambda expressions
[25]constexpr
changes:
goto
s in constexpr
functions
[27]static
and thread_local
variables that are usable in constant expressions in constexpr
functions
[28]constexpr
function does not need its return type and parameter types to be literal typeconstexpr
function for which no invocation satisfies the requirements of a core constant expression
[29]bool
in static_assert
and if constexpr
[30]std
and std.compat
[38]std::generator
for ranges
[39]std::expected
[40]std::optional
[41] and std::expected
[42]std::to_underlying
to get the underlying value of enum
[43]std::move_only_function
[44]std::forward_like
[45]std::invoke_r
[46]std::bind_back
[47]std::byteswap
[48]std::unreachable
: a function to mark
unreachable code
[49]std::tuple
compatible with other tuple-like objects
[50]std::basic_common_reference
specialization for std::reference_wrapper
yielding reference types
[51]std::pair
's forwarding constructor
[52]constexpr
support for:
std::ranges::to
[62]std::ranges::range_adaptor_closure
, a helper for defining user-defined range adaptor closures
[47]std::views::zip
and other variantsstd::views::adjacent
and other variants
[68]std::views::join_with
[69]std::views::slide
std::views::chunk
[70]std::views::chunk_by
[71]std::views::as_rvalue
[72]std::views::as_const
[73]std::views::repeat
[74]std::views::stride
[75]std::views::cartesian_product
[76]std::views::enumerate
[77]std::ranges::cbegin
and other similar utilities returning constant iterators should be fully guaranteed even for shallow-const views (such as std::span
)
[73]explicit
[80]std::out_ptr
and std::inout_ptr
for C interoperability
[81]std::allocate_at_least
and std::allocator::allocate_at_least
[82]std::start_lifetime_as
for implicit-lifetime types
[83]std::allocator_traits
[84]std::basic_string_view::contains
and std::basic_string::contains
[85]nullptr
for std::basic_string
and std::basic_string_view
[86]std::basic_string_view
[87]std::basic_string::resize_and_overwrite
[88]std::basic_string::substr
for efficient slicing
[89]std::thread::id
, and stacktraces.
[90]
[91]
[92]std::print
and std::println
from new header <print>
[94]std::span
-based string stream) from new header <spanstream>
[95]std::fstream
s
[96]std::basic_ostream::operator<<(const volatile void*)
[97]std::mdspan
[98]
[99]
[100]
[101]std::span
and std::basic_string_view
to be trivially copyable
[107]<stdatomic.h>
[108]char8_t
[115]wchar_t
to match existing practices
[116]this
or unknown origin in constant expressions
[117]static_assert(false)
in uninstantiated template contextsstd::counted_iterator
[120]std::ranges::join_view
[121]std::ranges::split_view
to std::ranges::lazy_split_view
and new split_view
[122]std::default_initializable
constraint from concept std::ranges::view
[123]std::ranges::owning_view
[124]std::ranges::istream_view
[125]std::basic_format_string
[126]std::format_to
[127]std::format
[130]constexpr
std::variant
and std::optional
[132]std::variant
in std::visit
[133]Removed features:
Deprecated features:
Reverted deprecated features:
operator[]
.<*.h>
headers for compatibility with C)-std=c++23
.
[140]-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
.
[141]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: [142]
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>
), based on
Boost.Stacktracestd::is_scoped_enum
<stdatomic.h>
, for interoperability with
C atomicsAfter the virtual WG21 meeting of 22 February 2021, following features are added where they were approved by straw polls: [143]
()
from
lambda expressions.counted_iterator
.time_point::clock
.
[144]std::visit
for classes that are derived from std::variant
.std::to_underlying
.After the summer 2021 ISO C++ standards plenary virtual meeting of June 2021, new features and defect reports were approved by straw polls: [146]
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.After the autumn 2021 ISO C++ standards plenary virtual meeting of October 2021, new features and defect reports were approved by straw polls: [147]
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.
[148]arr1, 2
).auto(x)
or auto{x}
.std::generator
-like types.std::pmr::stacktrace
which is equivalent to std::basic_stacktrace<std::pmr::polymorphic_allocator>
.
[149]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_view
zip_transform_view
adjacent_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
.
[150]After the virtual WG21 meeting of 7 February 2022, the following features are added where they were approved by straw polls: [153]
std::expected
constexpr
for cmath
and cstdlib
ranges::to
std::unique_ptr
constexpr
ranges::iota
, ranges::shift_left
and ranges::shift_right
views::join_with
views::chunk
and views::slide
views::chunk_by
After the virtual WG21 meeting of 25 July 2022, the following features and defect reports are added where they were approved by straw polls: [154]
volatile
variables.#warning
preprocessor directive.constexpr
functions to never be constant expressions.U'\N{LATIN CAPITAL LETTER A WITH MACRON}' // Equivalent to U'\u0100'
operator()
and lambdas to be
static
.
this
pointer and
references of unknown origin to appear in constant expressions.std::float16_t
, std::float32_t
, std::float64_t
, std::float128_t
,
std::bfloat16_t
for these extended types accessible through the header <stdfloat>
, their corresponding literal suffixes f16
f32
f64
f128
bf16
or F16
F32
F64
F128
BF16
and added overloads to various standard library functions that take floats as arguments.[[assume(expression)]]
attribute which allows the compiler to assume the provided expression is true to allow optimizations.char
and unsigned char
to be initialized with UTF-8
string literals.wchar_t
can encode all characters of the extended character set, in effect allowing UTF-16 to be used for wide string literals.std::mdspan
, a multidimensional array view analogous to std::span
.flat_map
and flat_set
were added to the standard library.std::print
and std::println
functions for printing formatted text to
stdout.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::string::substr
use
move semantics.std::generator
which implements 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.After the hybrid WG21 meeting of 7 November 2022, the following features and defect reports are added where they were approved by straw polls: [155]
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.
[156]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: [157]
views::enumerate
std::format
std::format
's width estimationstd::format
fill character allowancesthread::id
and stacktrace
std::is_implicit_lifetime
std::common_reference_t
of std::reference_wrapper
should be a reference typestd::allocator_traits
std::pmr::generator
std::numeric_limits::has_denorm
std::barrier
's phase completion guaranteesstatic constexpr
variables in constexpr
functions". 2022-11-07.
std::expected
".
mdspan
: rename pointer
and contiguous
". 15 June 2022.
empty
to mdspan
".
char8_t
Compatibility and Portability Fix". 2022-06-17.
wchar_t
to match existing practices" (PDF). 2022-07-15.
consteval
needs to propagate up". 2022-11-11.