Английская Википедия:C++23
Шаблон:Short description Шаблон:Multiple issues
Шаблон:C++ language revisions 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 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]
Modern "Hello, world" Example
After many library changes applied to the working draft, the new "Hello, world" program will be:
import std;
int main()
{
std::println("Hello, world!");
}
Features
Changes that have been accepted into C++23 include:
Language
- explicit
this
object parameter[9] if consteval
[10]- multidimensional subscript operator[11]
- static call and subscript operators and static lambdas[12][13]
- simplifying implicit move[14]
auto(x)
andauto{x}
[15]- new preprocessor directives:
- extending the lifetime of some temporaries in range-based for loop[18]
- new standard attribute
[[assume(expression)]]
[19] - class template argument deduction from inherited constructors[20]
- labels at the end of the compound statement[21]
- alias declarations in init-statements[22]
- literal suffixes for
std::size_t
and the corresponding signed type[23] - extended floating-point types with literals (conditionally supported)[24]
- optional
()
from nullary lambda expressions[25] - attributes on lambda expressions[26]
constexpr
changes:- non-literal variables, labels, and
goto
s inconstexpr
functions[27] - allowing
static
andthread_local
variables that are usable in constant expressions inconstexpr
functions[28] 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[29]
- non-literal variables, labels, and
- narrowing contextual conversions to
bool
instatic_assert
andif constexpr
[30] - trimming whitespaces before line splicing[31]
- make declaration order layout mandated[32]
- delimited escape sequences[33]
- named universal character escapes[34]
- text encoding changes:
Library
Standard Library Module Support
- standard library modules
std
andstd.compat
[38]
Coroutine Library Support
- synchronous coroutine
std::generator
for ranges[39]
General Utilities Support
- result type
std::expected
[40] - monadic operations for
std::optional
[41] andstd::expected
[42] - utility function
std::to_underlying
to get the underlying value of enum[43] - move-only callable wrapper
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]- made
std::tuple
compatible with other tuple-like objects[50] std::basic_common_reference
specialization forstd::reference_wrapper
yielding reference types[51]- adding default arguments for
std::pair
's forwarding constructor[52]
Compile-time Support
constexpr
support for:- metaprogramming utilities:
- adding move-only types support for comparison concepts[61]
Iterators, Ranges, and Algorithm Support
- new range conversion function
std::ranges::to
[62] - new constrained ranges algorithm:
- new
std::ranges::range_adaptor_closure
, a helper for defining user-defined range adaptor closures[47] - new range adaptors:
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]
- 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 asstd::span
)[73] - ranges iterators as inputs to non-ranges algorithms[78]
- relaxing range adaptors to allow for move only types[79]
- making multi-param constructors of some views
explicit
[80]
Memory Management Support
std::out_ptr
andstd::inout_ptr
for C interoperability[81]std::allocate_at_least
andstd::allocator::allocate_at_least
[82]- explicit lifetime management function
std::start_lifetime_as
for implicit-lifetime types[83] - disallowing user specialization of
std::allocator_traits
[84]
String and Text Processing Support
- new member functions and changes in string types:
std::basic_string_view::contains
andstd::basic_string::contains
[85]- disabling construction from
nullptr
forstd::basic_string
andstd::basic_string_view
[86] - explicit range constructor for
std::basic_string_view
[87] std::basic_string::resize_and_overwrite
[88]- rvalue reference overload of
std::basic_string::substr
for efficient slicing[89]
- formatting ranges, tuples, escaped presentation of characters and strings,
std::thread::id
, and stacktraces.[90][91][92]
Diagnostic Support
- stacktrace library[93]
I/O Support
- formatted output functions
std::print
andstd::println
from new header<print>
[94] - spanstream library (
std::span
-based string stream) from new header<spanstream>
[95] - a support for exclusive mode in
std::fstream
s[96] std::basic_ostream::operator<<(const volatile void*)
[97]
Containers Support
- multidimensional-span
std::mdspan
[98][99][100][101] - constructability and assignability of containers from other compatible ranges[62]
- flat set and flat map container adapters[102][103]
- non-deduction context for allocators in container deduction guides[104]
- heterogeneous erasure overloads for associative containers[105]
- allowing iterator pair construction in stack and queue[106]
- requiring
std::span
andstd::basic_string_view
to be trivially copyable[107]
C-Compatibility Support
- new header
<stdatomic.h>
[108]
Language defect reports
- C++ identifier syntax using Unicode Standard Annex 31[109]
- allowing duplicate attributes[110]
- changing scope of lambda trailing return type[111]
- making overloaded comparison operators less breaking change[112]
- undeprecating volatile compound assignments[113][114]
- fixing the compatibility and portability of
char8_t
[115] - relaxing requirements on
wchar_t
to match existing practices[116] - allowing some pointers and references of
this
or unknown origin in constant expressions[117] - introduction of immediate-escalating functions promoted to immediate functions[118]
- allowing
static_assert(false)
in uninstantiated template contexts
Library defect reports
- changes in ranges library:
- conditionally borrowed ranges[119]
- repairing input range adaptors and
std::counted_iterator
[120] - relaxing the constraint on
std::ranges::join_view
[121] - renamed
std::ranges::split_view
tostd::ranges::lazy_split_view
and newsplit_view
[122] - removed
std::default_initializable
constraint from conceptstd::ranges::view
[123] - view with ownership and new
std::ranges::owning_view
[124] - fixed
std::ranges::istream_view
[125]
- changes in text formatting library:
std::basic_format_string
[126]- compile-time format string checks
- reducing binary code size of
std::format_to
[127] - fixing locale handling in chrono formatters[128]
- improving width estimation[129] and fill character allowances of
std::format
[130] - use of forwarding references in format arguments to allow non-const-formattable types[131]
- fully
constexpr
std::variant
andstd::optional
[132] - supporting types derived from
std::variant
instd::visit
[133]
Removed features and deprecation
Removed features:
- Garbage Collection Support and Reachability-Based Leak Detection. It was added to the standard since C++11 but no compilers support this feature until C++23.[134]
- Mixed wide string literal concatenation.[135]
- Non-encodable wide character literals and multicharacter wide character literals.[136]
Deprecated features:
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[139]
Compiler support
- 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
. [140]
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.
The following were added after the virtual WG21 meeting of 9 November 2020, where they were approved by straw polls:[141]
- Literal suffixes for
std::size_t
and the corresponding signed type - A member function Шаблон:Cpp for Шаблон:Cpp and Шаблон:Cpp, to check whether or not the string contains a given substring or character
- A stacktrace library (Шаблон:Cpp), based on Boost.Stacktrace
- A type trait Шаблон:Cpp
- The header Шаблон:Cpp, for interoperability with C atomics
After the virtual WG21 meeting of 22 February 2021, following features are added where they were approved by straw polls:[142]
- Removing unnecessary empty parameter list Шаблон:Cpp from lambda expressions.
- Repairing input range adaptors and Шаблон:Cpp.
- Relax the requirements for Шаблон:Cpp.[143]
- Шаблон:Cpp for classes that are derived from Шаблон:Cpp.
- Locks lock lockables.[144]
- Conditionally borrowed ranges.
- Шаблон:Cpp.
After the summer 2021 ISO C++ standards plenary virtual meeting of June 2021, new features and defect reports were approved by straw polls:[145]
- Consteval if (Шаблон:Cpp).
- Narrowing contextual conversions to Шаблон:Cpp.
- Allowing duplicate attributes.
- Шаблон:Cpp-based string-stream (Шаблон:Cpp).
- Шаблон:Cpp and Шаблон:Cpp.
- [[constexpr|Шаблон:Code]] for Шаблон:Cpp, Шаблон:Cpp, and Шаблон:Cpp.
- Iterators pair constructors for Шаблон:Cpp (stack) and Шаблон:Cpp (queue).
- Few changes of the ranges library:
- Generalized Шаблон:Cpp and Шаблон:Cpp for arbitrary ranges.
- Renamed Шаблон:Cpp to Шаблон:Cpp and new Шаблон:Cpp.
- Relaxing the constraint on Шаблон:Cpp.
- Removing Шаблон:Cpp constraint from concept Шаблон:Cpp.
- Range constructor for Шаблон:Cpp.
- Prohibiting Шаблон:Cpp and Шаблон:Cpp construction from [[nullptr|Шаблон:Code]].
- Шаблон:Cpp.
- Improvements on Шаблон:Cpp.
- Adding default arguments for Шаблон:Cpp'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:[146]
- Non-literal variables, labels, and gotos in Шаблон:Cpp functions, but still ill-formed to evaluate them at compile-time.
- Explicit [[this (computer programming)|Шаблон:Code]] object parameter.
- Changes on character sets and encodings.
- New preprocessors: Шаблон:Cpp and Шаблон:Cpp. Both directives were added to C23 (C language update) and GCC 12.[147]
- Allowing alias declarations in init-statement.
- Overloading multidimensional subscript operator (e.g. Шаблон:Cpp).
- Decay copy in language: Шаблон:Cpp or Шаблон:Cpp.
- Changes in text formatting library:
- Fixing locale handling in chrono formatters.
- Use of forwarding references in format arguments to allow Шаблон:Cpp-like types.
- Addition of type alias Шаблон:Cpp which is equivalent to Шаблон:Cpp.[148]
- Changes in ranges library:
- Refined definition of a view.
- Replacing function template Шаблон:Cpp with alias templates Шаблон:Cpp, Шаблон:Cpp, and customization point object Шаблон:Cpp.
- Шаблон:Cpp range adaptor family:
- Шаблон:Cpp
- Шаблон:Cpp
- Шаблон:Cpp (and Шаблон:Cpp being equivalent to Шаблон:Cpp)
- Шаблон:Cpp (and Шаблон:Cpp being equivalent to Шаблон:Cpp)
- Шаблон:Cpp.
- Monadic operations for Шаблон:Cpp.
- Member function template Шаблон:Cpp.
- Printing [[volatile (computer programming)|Шаблон:Code]] pointers (Шаблон:Cpp).
- Шаблон:Cpp.
- Heterogeneous erasure overloads for associative containers.
- Every specialization of Шаблон:Cpp and Шаблон:Cpp is trivially copyable.
- Adding conditional Шаблон:Cpp specifications to Шаблон:Cpp.[149]
- Revamped specification and use of integer-class types.[150]
- 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."[151]
After the virtual WG21 meeting of 7 February 2022, the following features are added where they were approved by straw polls:[152]
- Allowed attributes on the function call operator of a lambda
- Шаблон:Cpp
- Шаблон:Cpp for
cmath
andcstdlib
- Function to mark unreachable code
- Шаблон:Cpp
- A type trait to detect reference binding to temporary
- Making Шаблон:Cpp Шаблон:Cpp
- Pipe support for user-defined range adaptors
- Шаблон:Cpp, Шаблон:Cpp and Шаблон:Cpp
- Шаблон:Cpp
- Windowing range adaptors: Шаблон:Cpp and Шаблон:Cpp
- Шаблон:Cpp
After the virtual WG21 meeting of 25 July 2022, the following features and defect reports are added where they were approved by straw polls:[153]
- Made rewriting equality in expressions less of a breaking change.
- Reverted the deprecation of bitwise assignment to Шаблон:Cpp variables.
- Added the Шаблон:Cpp preprocessor 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 Шаблон:Cpp functions to never be constant expressions.
- Simplified some implicit move rules from C++20 and allowed implicit move when returning an rvalue reference.
- Add a way to specify unicode characters by name. For example, Шаблон:Cpp
- Allowed [[operators in C and C++|Шаблон:Code]] and lambdas to be [[static (keyword)|Шаблон:Code]].
- Allowed the
this
pointer and references of unknown origin to appear in constant expressions. - 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. - Added the Шаблон:Cpp attribute which allows the compiler to assume the provided expression is true to allow optimizations.
- Made support for UTF-8 source files mandatory, providing a portable encoding for source files.
- Allowed arrays of Шаблон:Cpp and Шаблон:Cpp to be initialized with UTF-8 string literals.
- Removed the requirement that [[wchar_t|Шаблон:Code]] 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 tostd::span
. - Шаблон:Cpp and Шаблон:Cpp were added to the standard library.
- Added the Шаблон:Cpp and Шаблон:Cpp functions for printing formatted text to stdout.
- Provide the named modules Шаблон:Cpp and Шаблон:Cpp for importing the standard library.
- Added support for exclusive mode
fstreams
, analogous to the "x" flag infopen
. - Allowed
std::format
to handle ranges, tuples, and other containers. - Added
std::forward_like
. - Made
std::string::substr
use move semantics. - Added Шаблон:Cpp which implements a coroutine generator that models Шаблон:Cpp
- Шаблон:Cpp, Шаблон:Cpp, Шаблон:Cpp, Шаблон:Cpp, Шаблон:Cpp.
- Added new algorithms: Шаблон:Cpp, Шаблон:Cpp, 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 ofstd::to_chars
andstd::from_chars
Шаблон:Cpp-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.
After the hybrid WG21 meeting of 7 November 2022, the following features and defect reports are added where they were approved by straw polls:[154]
- Allowed Шаблон:Cpp to be Шаблон:Cpp.
- Allowed Шаблон:Cpp and [[thread-local storage|Шаблон:Code]] variables to appear in Шаблон:Cpp functions if they are usable in constant expressions.
- [[consteval|Шаблон:Code]] propagates upwards, that is, certain existing Шаблон:Cpp functions become Шаблон:Cpp 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 Шаблон:Cpp loop to cover the entire loop.
- Reverted the deprecation of (all, not just bitwise) compound assignment to Шаблон:Cpp variables.
- Monadic functions for Шаблон:Cpp.
- Synchronize the output of Шаблон:Cpp with the underlying stream if the native Unicode API is used.[155]
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:[156]
- Referencing the Unicode Standard.[157]
- Stashing stashing iterators for proper flattening.[158]
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
andstacktrace
- A type trait
std::is_implicit_lifetime
std::common_reference_t
ofstd::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
References
Шаблон:C++ programming language
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 6,0 6,1 Шаблон:Cite web
- ↑ 7,0 7,1 7,2 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 47,0 47,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 62,0 62,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 73,0 73,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- Английская Википедия
- C++
- C++ programming language family
- Algol programming language family
- High-level programming languages
- Statically typed programming languages
- Страницы, где используется шаблон "Навигационная таблица/Телепорт"
- Страницы с телепортом
- Википедия
- Статья из Википедии
- Статья из Английской Википедии