C 20
   HOME

TheInfoList



OR:

C++20 is a version of the
ISO ISO is the most common abbreviation for the International Organization for Standardization. ISO or Iso may also refer to: Business and finance * Iso (supermarket), a chain of Danish supermarkets incorporated into the SuperBest chain in 2007 * Iso ...
/
IEC The International Electrotechnical Commission (IEC; in French: ''Commission électrotechnique internationale'') is an international standards organization that prepares and publishes international standards for all electrical, electronic and r ...
14882 standard for the
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
programming language. C++20 replaced the prior version of the C++ standard, called
C++17 C++17 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++17 replaced the prior version of the C++ standard, called C++14, and was later replaced by C++20. History Before the C++ Standards Committee fixed a 3-year rel ...
. The standard was technically finalized by WG21 at the meeting in
Prague Prague ( ; cs, Praha ; german: Prag, ; la, Praga) is the capital and largest city in the Czech Republic, and the historical capital of Bohemia. On the Vltava river, Prague is home to about 1.3 million people. The city has a temperate ...
in February 2020, approved on 4 September 2020, and published in December 2020.


Features

C++20 adds more new major features than
C++14 C++14 is a version of the ISO/IEC 14882 standard for the C++ programming language. It is intended to be a small extension over C++11, featuring mainly bug fixes and small improvements, and was replaced by C++17. Its approval was announced on Augus ...
or
C++17 C++17 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++17 replaced the prior version of the C++ standard, called C++14, and was later replaced by C++20. History Before the C++ Standards Committee fixed a 3-year rel ...
. Changes that have been accepted into C++20 include:


Language

*
concepts Concepts are defined as abstract ideas. They are understood to be the fundamental building blocks of the concept behind principles, thoughts and beliefs. They play an important role in all aspects of cognition. As such, concepts are studied by sev ...
, with terse syntax *
modules Broadly speaking, modularity is the degree to which a system's components may be separated and recombined, often with the benefit of flexibility and variety in use. The concept of modularity is used primarily to reduce complexity by breaking a sy ...
* designated initializers (based on the
C99 C99 (previously known as C9X) is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard. It extends the previous version ( C90) with new features for the language and the standard library, and helps impl ...
feature, and common g++ extension) * , this/code> as a lambda capture * template parameter lists on lambdas *
three-way comparison In computer science, a three-way comparison takes two values A and B belonging to a type with a total order and determines whether A < B, A = B, or A > B in a single operation, in accordance with the mathematical law of trichotomy. Machine ...
using the "spaceship operator", operator <=> * initialization of an additional variable within a range-based for statement * lambdas in unevaluated contexts * default constructible and assignable stateless lambdas * allow pack expansions in lambda ''init-capture'' * class types in non-type template parameters, also allowing string literals as template parameters * removing the need for typename in certain circumstances * new standard attributes no_unique_address, likely and unlikely * conditional explicit, allowing the explicit modifier to be contingent on a boolean expression * expanded constexpr: virtual functions, union, try and catch, dynamic_cast and typeid, std::pointer_traits * immediate functions using the new consteval keyword *
signed integer In computer science, an integer is a datum of integral data type, a data type that represents some range of mathematical integers. Integral data types may be of different sizes and may or may not be allowed to contain negative values. Integers are ...
s are now defined to be represented using
two's complement Two's complement is a mathematical operation to reversibly convert a positive binary number into a negative binary number with equivalent (but negative) value, using the binary digit with the greatest place value (the leftmost bit in big- endian ...
(signed integer overflow remains
undefined behavior In computer programming, undefined behavior (UB) is the result of executing a program whose behavior is prescribed to be unpredictable, in the language specification to which the computer code adheres. This is different from unspecified behavior, ...
) * a revised memory model * various improvements to structured bindings (interaction with lambda captures, static and thread_local storage duration) *
coroutine Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative ...
s * using on scoped enums * constinit keyword


Library

* ranges (The One Ranges Proposal) * std::make_shared and std::allocate_shared for arrays * atomic smart pointers (such as std::atomic> and std::atomic>) * std::to_address to convert a pointer to a raw pointer * calendar and time-zone additions to * std::span, providing a view to a contiguous array (analogous to std::string_view but span can mutate the referenced sequence) * std::erase and std::erase_if, simplifying element erasure for most standard containers * header * std::bit_cast<> for type casting of object representations, with less verbosity than memcpy() and more ability to exploit compiler internals * feature test macros * various constexpr library bits * smart pointer creation with default initialization * contains-method for associative containers * bit operations, such as leading/trailing zero/one count, and log2 operations * std::bind_front


New and changed keywords

Many new keywords added (and the new "spaceship operator", operator <=>), such as concept, constinit, consteval, co_await, co_return, co_yield, requires (plus changed meaning for export), and char8_t (for
UTF-8 UTF-8 is a variable-width encoding, variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode'' (or ''Universal Coded Character Set'') ''Transformation Format 8-bit'' ...
support). And explicit can take an expression since C++20. Most of the uses of the volatile keyword have been deprecated. 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


Removed and deprecated

Removed features: * The C-derived headers , , , and 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 * (most of) volatile has been deprecated


Published as Technical Specifications

* Parallelism TS v2 (including task blocks) * Reflection TS v1 * Networking TS v1


Deferred to a later standard

* Contracts a new study group (SG21) has been formed to work on a new proposal * Reflection *
Metaclass In object-oriented programming, a metaclass is a class whose instances are classes. Just as an ordinary class defines the behavior of certain objects, a metaclass defines the behavior of certain classes and their instances. Not all object-oriente ...
es * Executors * Networking extensions, including async, basic I/O services, timers, buffers and buffer-oriented streams, sockets, and Internet protocols (blocked by executors) * Properties * Extended futures


Compiler support

Full support *
Visual Studio 2019 Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs including websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development platforms such ...
supports all C++20 features through its /std:c++latest option, as of version 16.10.0. An option /std:c++20 to enable C++20 mode is added in version 16.11.0. Microsoft's compiler doesn't just support Windows, also Linux (and e.g. Android and iOS), while it then requires the "Visual C++ for Linux Development extension". Partial *
Clang Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages, as well as the OpenMP, OpenCL, RenderScript, CUDA, and HIP frameworks. It acts as a drop-in replacement for the GNU Compiler Collection (GCC), ...
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). * EDG eccp started implementing C++20 features in version 5.0 and as of version 6.1 supports most C++20 core language features. * GCC added partial, experimental C++20 support in 2017 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.


History

Changes applied to the C++20 working draft in July 2017 (Toronto) include: *
concepts Concepts are defined as abstract ideas. They are understood to be the fundamental building blocks of the concept behind principles, thoughts and beliefs. They play an important role in all aspects of cognition. As such, concepts are studied by sev ...
(what made it into the standard is a cut-down version; also described as "Concepts Lite") * designated initializers * , this/code> 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: *
three-way comparison In computer science, a three-way comparison takes two values A and B belonging to a type with a total order and determines whether A < B, A = B, or A > B in a single operation, in accordance with the mathematical law of trichotomy. Machine ...
using the "spaceship operator", operator <=> * initialization of an additional variable within a range-based for statement * lambdas in unevaluated contexts * default constructible and assignable stateless lambdas * allow pack expansions in lambda ''init-capture'' * string literals as template parameters * atomic smart pointers (such as std::atomic> and std::atomic>) * std::to_address to convert a pointer to a raw pointer Changes applied to the C++20 working draft in March 2018 (Jacksonville) include: * removing the need for typename in certain circumstances * new standard attributes no_unique_address, likely and unlikely * calendar and time-zone additions to * std::span, providing a view to a contiguous array (analogous to std::string_view but span can mutate the referenced sequence) * header Changes applied to the C++20 working draft in the summer meeting in June 2018 (Rapperswil) include: * contracts ( later deferred to a later standard) * feature test macros * bit-casting of object representations, with less verbosity than memcpy() and more ability to exploit compiler internals * conditional explicit, allowing the explicit modifier to be contingent on a boolean expression * constexpr virtual functions Changes applied to the C++20 working draft in the fall meeting in November 2018 (San Diego) include: * ranges (The One Ranges Proposal) * concept terse syntax * constexpr union, try and catch, dynamic_cast, typeid and std::pointer_traits. * various constexpr library bits * immediate functions using the new consteval keyword *
signed integer In computer science, an integer is a datum of integral data type, a data type that represents some range of mathematical integers. Integral data types may be of different sizes and may or may not be allowed to contain negative values. Integers are ...
s are now defined to be represented using
two's complement Two's complement is a mathematical operation to reversibly convert a positive binary number into a negative binary number with equivalent (but negative) value, using the binary digit with the greatest place value (the leftmost bit in big- endian ...
(signed integer overflow remains
undefined behavior In computer programming, undefined behavior (UB) is the result of executing a program whose behavior is prescribed to be unpredictable, in the language specification to which the computer code adheres. This is different from unspecified behavior, ...
) * refinements of the contracts facility (access control in contract conditions) (see list of features deferred to a later standard) * a revised memory model * smart pointer creation with default initialization Changes applied to the C++20 working draft in the winter meeting in February 2019 (Kona) include: *
coroutine Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative ...
s *
modules Broadly speaking, modularity is the degree to which a system's components may be separated and recombined, often with the benefit of flexibility and variety in use. The concept of modularity is used primarily to reduce complexity by breaking a sy ...
* various improvements to structured bindings (interaction with lambda captures, static and thread_local storage duration) Changes applied to the C++20 working draft in the summer meeting in July 2019 (Cologne) include: * contracts were removed (see list of features deferred to a later standard) * use of comma operator in subscript expressions has been deprecated * constexpr additions (trivial default initialization, unevaluated inline-assembly) * using scoped enums * various changes to the spaceship operator * DR: minor changes to modules * constinit keyword * changes to concepts (removal of -> Type return-type-requirements) * (most of) volatile has been deprecated * DR: nodiscard effects on constructors * The new standard library concepts will not use
PascalCase Camel case (sometimes stylized as camelCase or CamelCase, also known as camel caps or more formally as medial capitals) is the practice of writing phrases without spaces or punctuation. The format indicates the separation of words with a single ...
(rather standard_case, as the rest of the standard library) * text formatting (chrono integration, corner case fixes) * bit operations * constexpr INVOKE * math constants * consistency additions to atomics (std::atomic_ref, std::atomic>) * add the <=> operator to the standard library * header units for the standard library * synchronization facilities (merged from: Efficient atomic waiting and semaphores, latches and barriers, Improving atomic_flag, Don't Make C++ Unimplementable On Small CPUs) * std::source_location * constexpr containers (std::string, std::vector) * std::stop_token and joining thread (std::jthread) Changes applied during the NB comment resolution in the fall meeting in November 2019 (Belfast) include: * 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

. This allows also for array members in class-type NTTP. * Floating-point types, 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 * std::spans
typedef typedef is a reserved keyword in the programming languages C, C++, and Objective-C. It is used to create an additional name (''alias'') for another data type, but does not create a new type, except in the obscure case of a qualified typedef of ...
was changed from index_type to size_type to be consistent with the rest of the standard library * 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, P1391R4: Range constructor for std::string_view (constructor from iterator-pair of characters), P1394R4: Range constructor for std::span<ref>, P1870R1: forwarding-range<T> is too subtle) * Initialization for std::atomic has been changed to make it work with default and list initialization, 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


References


External links


Link to purchase ISO/IEC 14882:2020
from the ISO online store.
N4860
the final draft version of the standard.
JTC1/SC22/WG21
the ISO/IEC C++ Standard Working Group (a.k.a. the C++ Standards Committee) * Ranges
range-v3
GitHub repository, by Eric Niebler {{ISO standards C++ C++ programming language family Programming language standards Programming languages created in 2020 IEC standards ISO standards