C++20 is a version of the
ISO/
IEC 14882 standard for the
C++ programming language. C++20 replaced the prior version of the C++ standard, called
C++17, and was later replaced by
C++23.[1] The standard was technically finalized[2] by
WG21 at the meeting in
Prague in February 2020,[3] had its final draft version announced in March 2020,[4] was approved on 4 September 2020,[5][6] and published in December 2020.[7]
Features
C++20 adds more new major features than
C++14 or
C++17.[8] Changes that have been accepted into C++20 include:[9]
Many new keywords added (and the new "spaceship operator", operator <=>), such as concept, constinit,[38]consteval, co_await, co_return, co_yield, requires (plus changed meaning for export), and char8_t (for
UTF-8 support).[57] And explicit can take an expression since C++20.[58] Most of the uses of the volatile keyword have been deprecated.[59]
In addition to keywords, there are identifiers with special meaning, including new import and module.
New attributes in C++20:
[[likely]], [[unlikely]], and [[no_unique_address]][60]
The
C-derived headers <ccomplex>, <ciso646>, <cstdalign>, <cstdbool> and <ctgmath> were removed, as they serve no purpose in C++. (The corresponding <*.h> headers remain, for compatibility with C.)
The use of throw() as an exception specification was removed.
Some previously deprecated library features were removed, including std::uncaught_exception, std::raw_storage_iterator, std::is_literal_type, std::is_literal_type_v, std::result_of and std::result_of_t.
Deprecated features:
Use of comma operator in subscript expressions has been deprecated[62]
Networking extensions,[72][73] including async, basic I/O services, timers, buffers and buffer-oriented streams, sockets, and Internet protocols (blocked by executors)
Visual Studio 2019 supports all C++20 features through its /std:c++latest option, as of version 16.10.0.[77] An option /std:c++20 to enable C++20 mode is added in version 16.11.0.[78][79]
Microsoft's compiler does not just support Windows, also Linux (and e.g. Android and iOS), while it then requires the "Visual C++ for Linux Development extension".[80]
Partial
Clang has partial C++20 support that can be enabled with the option -std=c++20 (version 10 and later) or -std=c++2a (version 9 and earlier).[81]
EDG started implementing C++20 features in version 5.0 and as of version 6.1 supports most C++20 core language features.[82]
GCC added partial, experimental C++20 support in 2017[83] in version 8 through the option -std=c++2a. Like Clang, GCC replaced this option with -std=c++20 in version 10. It also has an option to enable GNU extensions in addition to the experimental C++20 support, -std=gnu++20.[84]
History
Changes applied to the C++20 working draft in July 2017 (Toronto) include:[85]
concepts (what made it into the standard is a cut-down version; also described as "Concepts Lite"[86])
designated initializers
[=, this] as a lambda capture
template parameter lists on lambdas
std::make_shared and std::allocate_shared for arrays
Changes applied to the C++20 working draft in the fall meeting in November 2017 (Albuquerque) include:[87][88]
synchronization facilities[120] (merged from: Efficient atomic waiting and semaphores,[121] latches and barriers,[122] Improving atomic_flag,[123] Don't Make C++ Unimplementable On Small CPUs[124])
std::stop_token and joining thread (std::jthread)[128]
Changes applied during the NB comment resolution in the fall meeting in November 2019 (Belfast) include:[129][130][131][132]
Class Types in Non-Type Template Parameters (NTTP): The restriction of no user-defined operator== allowed has been removed as the meaning of template argument equality has been divorced from operator==.[133] This allows also for array members in class-type NTTP.
Floating-point types,[134] pointers and references and unions and union-like classes (class types containing anonymous unions) are now allowed as NTTP.
Function identity now also includes trailing requires-clauses (P1971)
Constrained non-template functions have been removed
<compare> is now available in freestanding implementations[135]
std::spans
typedef was changed from index_type to size_type to be consistent with the rest of the standard library[136]
Concept traits have been renamed to follow the renaming of the concepts as a result from the Cologne meeting
Several fixes and additions to ranges (P1456R1: Move-only views,[137] P1391R4: Range constructor for std::string_view (constructor from iterator-pair of characters),[138] P1394R4: Range constructor for std::span<ref>,[139] P1870R1: forwarding-range<T> is too subtle[140])
Initialization for std::atomic<T> has been changed to make it work with default and list initialization,[141]std::latch and std::barrier can now report the maximum number of threads that the implementation supports through the new member function max()
std::weak_equality and std::strong_equality have been removed as they are not used anymore
Algorithms in <numeric> have been made constexpr
Missing feature-test macros for new or changed features of C++20 have been added[142]
References
^"The Standard". isocpp.org.
Archived from the original on 19 September 2020. Retrieved 7 September 2020.
^Meredith, Alisdair; Sutter, Herb.
"Revising atomic_shared_ptr for C++20". JTC1/SC22/WG21 - The C++ Standards Committee - ISOCPP.
ISO.
Archived from the original on 4 January 2018. Retrieved 27 December 2018.
C++20 is a version of the
ISO/
IEC 14882 standard for the
C++ programming language. C++20 replaced the prior version of the C++ standard, called
C++17, and was later replaced by
C++23.[1] The standard was technically finalized[2] by
WG21 at the meeting in
Prague in February 2020,[3] had its final draft version announced in March 2020,[4] was approved on 4 September 2020,[5][6] and published in December 2020.[7]
Features
C++20 adds more new major features than
C++14 or
C++17.[8] Changes that have been accepted into C++20 include:[9]
Many new keywords added (and the new "spaceship operator", operator <=>), such as concept, constinit,[38]consteval, co_await, co_return, co_yield, requires (plus changed meaning for export), and char8_t (for
UTF-8 support).[57] And explicit can take an expression since C++20.[58] Most of the uses of the volatile keyword have been deprecated.[59]
In addition to keywords, there are identifiers with special meaning, including new import and module.
New attributes in C++20:
[[likely]], [[unlikely]], and [[no_unique_address]][60]
The
C-derived headers <ccomplex>, <ciso646>, <cstdalign>, <cstdbool> and <ctgmath> were removed, as they serve no purpose in C++. (The corresponding <*.h> headers remain, for compatibility with C.)
The use of throw() as an exception specification was removed.
Some previously deprecated library features were removed, including std::uncaught_exception, std::raw_storage_iterator, std::is_literal_type, std::is_literal_type_v, std::result_of and std::result_of_t.
Deprecated features:
Use of comma operator in subscript expressions has been deprecated[62]
Networking extensions,[72][73] including async, basic I/O services, timers, buffers and buffer-oriented streams, sockets, and Internet protocols (blocked by executors)
Visual Studio 2019 supports all C++20 features through its /std:c++latest option, as of version 16.10.0.[77] An option /std:c++20 to enable C++20 mode is added in version 16.11.0.[78][79]
Microsoft's compiler does not just support Windows, also Linux (and e.g. Android and iOS), while it then requires the "Visual C++ for Linux Development extension".[80]
Partial
Clang has partial C++20 support that can be enabled with the option -std=c++20 (version 10 and later) or -std=c++2a (version 9 and earlier).[81]
EDG started implementing C++20 features in version 5.0 and as of version 6.1 supports most C++20 core language features.[82]
GCC added partial, experimental C++20 support in 2017[83] in version 8 through the option -std=c++2a. Like Clang, GCC replaced this option with -std=c++20 in version 10. It also has an option to enable GNU extensions in addition to the experimental C++20 support, -std=gnu++20.[84]
History
Changes applied to the C++20 working draft in July 2017 (Toronto) include:[85]
concepts (what made it into the standard is a cut-down version; also described as "Concepts Lite"[86])
designated initializers
[=, this] as a lambda capture
template parameter lists on lambdas
std::make_shared and std::allocate_shared for arrays
Changes applied to the C++20 working draft in the fall meeting in November 2017 (Albuquerque) include:[87][88]
synchronization facilities[120] (merged from: Efficient atomic waiting and semaphores,[121] latches and barriers,[122] Improving atomic_flag,[123] Don't Make C++ Unimplementable On Small CPUs[124])
std::stop_token and joining thread (std::jthread)[128]
Changes applied during the NB comment resolution in the fall meeting in November 2019 (Belfast) include:[129][130][131][132]
Class Types in Non-Type Template Parameters (NTTP): The restriction of no user-defined operator== allowed has been removed as the meaning of template argument equality has been divorced from operator==.[133] This allows also for array members in class-type NTTP.
Floating-point types,[134] pointers and references and unions and union-like classes (class types containing anonymous unions) are now allowed as NTTP.
Function identity now also includes trailing requires-clauses (P1971)
Constrained non-template functions have been removed
<compare> is now available in freestanding implementations[135]
std::spans
typedef was changed from index_type to size_type to be consistent with the rest of the standard library[136]
Concept traits have been renamed to follow the renaming of the concepts as a result from the Cologne meeting
Several fixes and additions to ranges (P1456R1: Move-only views,[137] P1391R4: Range constructor for std::string_view (constructor from iterator-pair of characters),[138] P1394R4: Range constructor for std::span<ref>,[139] P1870R1: forwarding-range<T> is too subtle[140])
Initialization for std::atomic<T> has been changed to make it work with default and list initialization,[141]std::latch and std::barrier can now report the maximum number of threads that the implementation supports through the new member function max()
std::weak_equality and std::strong_equality have been removed as they are not used anymore
Algorithms in <numeric> have been made constexpr
Missing feature-test macros for new or changed features of C++20 have been added[142]
References
^"The Standard". isocpp.org.
Archived from the original on 19 September 2020. Retrieved 7 September 2020.
^Meredith, Alisdair; Sutter, Herb.
"Revising atomic_shared_ptr for C++20". JTC1/SC22/WG21 - The C++ Standards Committee - ISOCPP.
ISO.
Archived from the original on 4 January 2018. Retrieved 27 December 2018.