C++23
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 current draft is N4944.[1]
C++ language revisions |
---|
In February 2020, at the final meeting for C++20 in Prague, an overall plan for C++23 was adopted:[2][3] 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,[4][5] as was the November 2020 meeting in New York[6][5] and the February 2021 meeting in Kona, Hawaii.[6] All meetings until November 2022 were virtual while the November 2022 meeting was hybrid.[6]
New features
In the absence of face-to-face WG21 meetings during the COVID pandemic, few new features were added to the C++23 draft in early standards meetings. The following were added after the virtual WG21 meeting of 9 November 2020, where they were approved by straw polls:[7]
- Literal suffixes for
std::size_t
and the corresponding signed type[8] - A member function
contains
forstd::basic_string
andstd::basic_string_view
, to check whether or not the string contains a given substring or character[9] - A stacktrace library (
<stacktrace>
), based on Boost.Stacktrace[10] - A type trait
std::is_scoped_enum
[11] - The header
<stdatomic.h>
, for interoperability with C atomics[12]
After the virtual WG21 meeting of 22 February 2021, following features are added where they were approved by straw polls:[13]
- Repairing input range adaptors and
counted_iterator
.[14] - Removing unnecessary empty parameter list
()
from lambda expressions.[15] - Relax the requirements for
time_point::clock
.[16] std::visit
for classes that are derived fromstd::variant
.[17]- Locks lock lockables.[18]
- Conditionally borrowed ranges.[19]
std::to_underlying
.[20]
After the summer 2021 ISO C++ standards plenary virtual meeting of June 2021, new features and defect reports were approved by straw polls:[21]
- Consteval if (
if consteval
).[22] - Narrowing contextual conversions to
bool
.[23] - Allowing duplicate attributes.[24]
std::span
-based string-stream (<spanstream>
).[25]std::out_ptr()
andstd::inout_ptr()
.[26]constexpr
forstd::optional
,std::variant
,[27] andstd::type_info::operator==
.[28]- Iterators pair constructors for
std::stack
(stack) andstd::queue
(queue).[29] - Few changes of the ranges library:
- Prohibiting
std::basic_string
andstd::basic_string_view
construction fromnullptr
.[35] std::invoke_r
.[36]- Improvements on
std::format
.[37] - Adding default arguments for
std::pair
's forwarding constructor.[38]
After the autumn 2021 ISO C++ standards plenary virtual meeting of October 2021, new features and defect reports were approved by straw polls:[39]
- Non-literal variables, labels, and gotos in
constexpr
functions, but still ill-formed to evaluate them at compile-time.[40] - Explicit
this
object parameter.[41] - Changes on character sets and encodings.[42][43]
- New preprocessors:
#elifdef
and#elifndef
.[44] Both directives were added to C23 (C language update) and GCC 12.[45] - Allowing alias declarations in init-statement.[46]
- Overloading multidimensional subscript operator (e.g.
arr[1, 2]
).[47] - Decay copy in language:
auto(x)
orauto{x<nowiki>}</nowiki>
.[48] - Changes in text formatting library:
- Addition of type alias
std::pmr::stacktrace
which is equivalent tostd::basic_stacktrace<std::pmr::polymorphic_allocator>
.[51] - Changes in ranges library:
- Refined definition of a view.[52]
- Replacing function template
std::ranges::istream_view
with alias templatesstd::ranges::istream_view
,std::ranges::wistream_view
, and customization point objectstd::views::istream
.[53] zip
range adaptor family:[54]zip_view
zip_transform_view
adjacent_view
(andstd::views::pairwise
being equivalent tostd::views::adjacent<2>
)adjacent_transform_view
(andstd::views::pairwise_transform
being equivalent tostd::views::adjacent_transform<2>
)
std::move_only_function
.[55]- Monadic operations for
std::optional
.[56] - Member function template
std::basic_string::resize_and_overwrite
.[57] - Printing
volatile
pointers (volatile T*
).[58] std::byteswap
.[59]- Heterogeneous erasure overloads for associative containers.[60]
- Every specialization of
std::span
andstd::basic_string_view
is trivially copyable.[61] - Adding conditional
noexcept
specifications tostd::exchange
.[62] - Revamped specification and use of integer-class types.[63]
- 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."[64]
After the virtual WG21 meeting of 7 February 2022, the following features are added where they were approved by straw polls:[65]
std::expected
[66]constexpr
forcmath
andcstdlib
[67]- Function to mark unreachable code[68]
ranges::to
[69]- A type trait to detect reference binding to temporary[70]
- Making
std::unique_ptr
constexpr
[71] - Pipe support for user-defined range adaptors[72]
ranges::iota
,ranges::shift_left
andranges::shift_right
[73]views::join_with
[74]- Windowing range adaptors:
views::chunk
andviews::slide
[75] views::chunk_by
[76]
After the virtual WG21 meeting of 25 July 2022, the following features and defect reports are added where they were approved by straw polls:[77]
- Made rewriting equality in expressions less of a breaking change.[78]
- Reverted the deprecation of bitwise assignment to
volatile
variables.[79] - Added the
#warning
preprocessor directive.[80] - Removed non-encodable wide character literals and multicharacter wide character literals.[81]
- Allowed labels to appear at the end of compound statements.[82]
- Added escape sequences delimited with curly braces for octal and hexadecimal numbers and universal character names.[83]
- Allowed
constexpr
functions to never be constant expressions.[84] - Simplified some implicit move rules from C++20 and allowed implicit move when returning an rvalue reference.[85]
- Add a way to specify unicode characters by name. For example,
U'\N{LATIN CAPITAL LETTER A WITH MACRON}' // Equivalent to U'\u0100'
[86] - Allowed operator
operator()
to bestatic
.[87] - Allowed the
this
pointer and references of unknown origin to appear in constant expressions.[88] - Allowed implementations to define extended floating-point 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<stdfloat>
, their corresponding literal suffixesf16
f32
f64
f128
bf16
orF16
F32
F64
F128
BF16
and added overloads to various standard library functions that take floats as arguments.[89] - Added the
[[assume(expression)]]
attribute which allows the compiler to assume the provided expression is true to allow optimizations.[90] - Made support for UTF-8 source files mandatory, providing a portable encoding for source files.[91]
- Allowed arrays of
char
andunsigned char
to be initialized with UTF-8 string literals.[92] - 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.[93] - Added
std::mdspan
, a multidimensional array view analogous tostd::span
.[94][95][96][97] flat_map
andflat_set
were added to the standard library.[98][99]- Added the
std::print
andstd::println
functions for printing formatted text to stdout.[100] - Provide the named modules
std
andstd.compat
for importing the standard library.[101] - Added support for exclusive mode
fstreams
, analogous to the "x" flag infopen
.[102] - Allowed
std::format
to handle Ranges.[103] - Made
std::string::substr
use move semantics.[104] - Added
std::generator
which implements a coroutine generator that modelsstd::ranges::input_range
[105]
After the hybrid WG21 meeting of 7 November 2022, the following features and defect reports are added where they were approved by straw polls:[106]
- Allowed operator
operator[]
to bestatic
.[107] - Allowed
static
andthread_local
variables to appear inconstexpr
functions if they are usable in constant expressions.[108] consteval
propagates upwards, that is, certain existingconstexpr
functions becomeconsteval
functions when those functions can already only be invoked during compile time.[109]- Extended the lifetime of temporaries that appear in the for-range-initializer of a range-based
for
loop to cover the entire loop.[110] - Monadic functions for
std::expected
.[111] - Synchronize the output of
std::print
with the underlying stream if the native Unicode API is used.[112] - Reverted the deprecation of (all, not just bitwise) compound assignment to
volatile
variables.[113]
Removed and deprecated features
- Removed the garbage collection support that was added in C++11, despite many GC implementations available for C++; "Garbage Collection in C++ is clearly useful for particular applications. However, Garbage Collection as specified by the Standard is not useful for those applications."[114]
- Deprecate
std::aligned_storage
andstd::aligned_union
[115]
References
- "Working Draft, Standard for Programming Language C++" (PDF). 2023-03-22.
- Dusíková, Hana (2019-11-06). "N4817: 2020 Prague Meeting Invitation and Information" (PDF). Archived (PDF) from the original on 2019-12-29. Retrieved 2020-02-13.
- Voutilainen, Ville (2019-11-25). "To boldly suggest an overall plan for C++23". www.open-std.org. Archived from the original on 2019-12-24. Retrieved 2020-02-13.
- "P2145R0: Evolving C++ Remotely". www.open-std.org.
- Sutter, Herb (29 July 2020). "Business Plan and Convener's Report: ISO/IEC JTC1/SC22/WG21 (C++)" (PDF).
- "Upcoming Meetings, Past Meetings : Standard C++". isocpp.org.
- Ranns, Nina (2020-11-19). "WG21 2020-11 Virtual Meeting: Minutes of Meeting" (PDF).
- JeanHeyd Meneide; Rein Halbersma (2019-11-24). "Literal Suffix for (signed) size_t".
- Wim Leflere; Paul Fee (2020-06-13). "string contains function".
- Alexey Gorgurov; Antony Polukhin (2020-09-16). "A Proposal to add stacktrace library".
- Juan Alday (2020-10-12). "A proposal for a type trait to detect scoped enumerations" (PDF).
- Hans-J. Boehm (2020-10-23). "P0943R6: Support C atomics in C++".
- Ranns, Nina (2021-02-22). "WG21 2021-02 Virtual Meeting: Minutes of Meeting" (PDF).
- Tim Song (2021-01-12). "Repairing input range adaptors and counted_iterator".
- Alex Christensen; JF Bastien (2020-12-11). "P1102R2: Down with ()!".
- Alexey Dmitriev; Howard Hinnant (2020-10-22). "Relax Requirements for time_point::clock".
- Barry Revzin (2020-10-30). "Inheriting from std::variant".
- Tim Song (2020-11-13). "Locks lock lockables".
- Barry Revzin (2020-02-19). "Conditionally borrowed ranges".
- JeanHeyd Meneide (2021-01-22). "std::to_underlying for enumerations".
- Ranns, Nina (2021-06-07). "WG21 2021-06 Virtual MeetingMinutes of Meeting" (PDF).
- Barry Revzin; Richard Smith; Andrew Sutton; Daveed Vandevoorde (2021-03-22). "if consteval".
- Andrzej Krzemieński (2021-04-12). "Narrowing contextual conversions to bool".
- Erich Keane (2020-07-02). "Allow Duplicate Attributes" (PDF).
- Peter Sommerlad (2021-02-26). "A strstream replacement using span<charT> as buffer" (PDF).
- JeanHeyd Meneide; Todor Buyukliev; Isabella Muerte (2021-04-15). "out_ptr - a scalable output pointer abstraction".
- Barry Revzin (2021-02-11). "Missing constexpr in std::optional and std::variant".
- Peter Dimov (2021-05-01). "Making std::type_info::operator== constexpr".
- Corentin Jabot (2021-03-05). "Iterators pair constructors for stack and queue" (PDF).
- Christopher Di Bella (2021-02-19). "starts_with and ends_with".
- Barry Revzin (2021-03-05). "Superior String Splitting".
- Tim Song (2021-05-06). "join_view should join all views of ranges".
- Barry Revzin (2021-05-14). "Views should not be required to be default constructible".
- Corentin Jabot (2021-03-17). "Range constructor forstd::string_view 2: Constrain Harder" (PDF).
- Yuriy Chernyshov (2020-09-06). "A Proposal to Prohibit std::basic_string and std::basic_string_view construction from nullptr".
- Zhihao Yuan (2020-04-29). "invoke_r".
- Victor Zverovich (2021-02-05). "std::format improvements".
- Logan R. Smith (2021-01-25). "Default Arguments for pair's Forwarding Constructor".
- Ranns, Nina (2021-10-04). "WG21 2021-10 Virtual Meeting Minutes of Meeting" (PDF).
- Ville Voutilainen (2021-07-12). "Non-literal variables (and labels and gotos) in constexpr functions".
- Gašper Ažman; Sy Brand; Ben Deane; Barry Revzin (2021-07-12). "Deducing this".
- Corentin Jabot (2021-09-14). "Consistent character literal encoding" (PDF).
- Jens Maurer (2021-09-21). "Character sets and encodings".
- Melanie Blower (2021-04-30). "Add support for preprocessing directives elifdef and elifndef" (PDF).
- "GCC 12 Adds Support For New #elifdef #elifndef Directives". phoronix. May 12, 2021. Archived from the original on December 27, 2022.
- Jens Maurer (2021-04-13). "Extend init-statement to allow alias-declaration".
- Mark Hoemmen; Daisy Hollman; Corentin Jabot; Isabella Muerte; Christian Trott (2021-09-14). "Multidimensional subscript operator" (PDF).
- Zhihao Yuan (2021-07-12). "auto(x): decay-copy in the language".
- Victor Zverovich; Corentin Jabot (2021-09-11). "Fixing locale handling in chrono formatters".
- Victor Zverovich (2021-09-24). "Add support for std::generator-like types to std::format".
- Steve Downey (2021-06-14). "Add a pmr alias for std::stacktrace".
- Barry Revzin; Tim Song (2021-08-15). "What is a view?".
- Nicolai Josuttis (2021-09-24). "Fix istream_view" (PDF).
- Tim Song (2021-06-11). "zip".
- Matt Calabrese; Ryan McDougall (2021-07-09). "move_only_function".
- Sy Brand (2021-04-27). "Monadic operations for std::optional".
- Chris Kennelly; Mark Zeren (2021-09-14). "basic_string::resize_and_overwrite".
- Bryce Adelstein Lelbach (2021-09-25). "Printing volatile Pointers".
- Isabella Muerte; Corentin Jabot (2021-09-17). "Byteswapping for fun&&nuf".
- Konstantin Boyarinov; Sergey Vinogradov; Ruslan Arutyunyan (2020-12-15). "Heterogeneous erasure overloads for associative containers".
- Nevin Liber (2021-03-19). "Require span & basic_string_view to be TriviallyCopyable" (PDF).
- Giuseppe D'Angelo (2021-06-28). "Add a conditional noexcept specification to std::exchange".
- Tim Song (2021-08-06). "Cleaning up integer-class types".
- Thomas Köppe (2021-06-11). "Clarifying the status of the "C headers"".
- Ranns, Nina (2022-02-07). "WG21 2022-02 Virtual Meeting: Minutes of Meeting" (PDF).
- Vicente Botet; JF Bastien; Jonathan Wakely (2022-01-07). "std::expected".
- Edward J. Rosten; Oliver J. Rosten (2021-11-12). "constexpr for <cmath> and <cstdlib>" (PDF).
- Melissa Mears; Jens Maurer (2021-10-15). "Function to mark unreachable code" (PDF).
- Corentin Jabot; Eric Niebler; Casey Carter (2022-01-21). "Conversions from ranges to containers" (PDF).
- Tim Song (2021-10-13). "A type trait to detect reference binding to temporary".
- Andreas Fertig (2021-11-06). "Making std::unique_ptr constexpr" (PDF).
- Barry Revzin (2021-12-17). "Pipe support for user-defined range adaptors".
- Tim Song (2021-12-05). "ranges::iota, ranges::shift_left, and ranges::shift_right".
- Barry Revzin (2022-01-28). "views::join_with".
- Tim Song (2021-12-05). "Windowing range adaptors: views::chunk and views::slide".
- Tim Song (2021-11-19). "views::chunk_by".
- Ranns, Nina (2022-08-09). "WG21 2022-07 Virtual Meeting: Minutes of Meeting" (PDF).
- "The Equality Operator You Are Looking For". 2022-01-13.
- "De-deprecating volatile compound operations" (PDF).
- "Support for #warning" (PDF). 2022-01-13.
- "Remove non-encodable wide character literals and multicharacter wide character literals" (PDF).
- "Labels at the end of compound statements (C compatibility)" (PDF). 2022-01-13.
- "Delimited escape sequences" (PDF). 2022-02-25.
- "Relaxing some constexpr restrictions". 2022-01-27.
- "Simpler implicit move". 2022-03-23.
- "Named universal character escapes". 2022-03-25.
- "static operator()". 2022-04-08.
- "Using unknown pointers and references in constant expressions".
- "Extended floating-point types and standard names". 2022-04-22.
- "Portable assumptions" (PDF). 2022-04-22.
- "Support for UTF-8 as a portable source file encoding" (PDF). 2022-07-01.
- "
char8_t
Compatibility and Portability Fix". 2022-06-17. - "Relax requirements on
wchar_t
to match existing practices" (PDF). 2022-07-15. - "MDSPAN".
- "index_type & size_type in mdspan" (PDF).
- "
mdspan
: renamepointer
andcontiguous
". - "Add the missing
empty
tomdspan
". - "A Standard flat_map" (PDF).
- "A Standard flat_set" (PDF).
- "Formatted output".
- "Standard Library Modules std and std.compat" (PDF).
- "Support exclusive mode for fstreams".
- "Formatting Ranges".
- "std::string::substr() &&".
- "(std::generator: Synchronous Coroutine Generator for Ranges)" (PDF).
- Ranns, Nina (2022-12-05). "WG21 2022-07 Virtual Meeting: Minutes of Meeting" (PDF).
- "static operator[]" (PDF). 2022-11-11.
- "Permitting
static constexpr
variables inconstexpr
functions". 2022-11-07. - "
consteval
needs to propagate up". 2022-11-11. - "Wording for P2644R1 Fix for Range-based for Loop". 2022-11-11.
- Jeff Garland (2022-09-28). "P2505R5 Monadic Functions for
std::expected
". - Victor Zverovich (2022-11-08). "Should the output of std::print to a terminal be synchronized with the underlying stream?".
- "Core Language Working Group NB comment resolutions for the November, 2022 meeting : 2654. Un-deprecation of compound volatile assignments".
- JF Bastien; Alisdair Meredith (2021-04-16). "Removing Garbage Collection Support".
- CJ Johnson (2021-11-22). "Deprecate std::aligned_storage and std::aligned_union" (PDF).