C++20

C++20 is the informal name for the revision of the ISO/IEC standard for the C++ programming language expected to follow C++17.[1] The standard became technically finalized[2] by WG21 at the meeting in Prague in February 2020.[3] The standard was expected to be officially published after the end of the DIS ballot in May 2020, but as of July 2020, it is still underway.[4]

C++20 adds more new major features than C++14 or C++17.[5] Below is a partial list of changes that have been accepted into or have been discussed for inclusion into C++20.[6]

New Features

C++20 introduced many new features. The following lists may be incomplete.

Language

  • concepts,[7] with terse syntax[8]
  • modules[9]
  • designated initializers[10] (based on the C99 feature, and common G++ extension)
  • [=, this] as a lambda capture[11]
  • template parameter lists on lambdas[12]
  • three-way comparison using the "spaceship operator", operator <=>
  • initialization of an additional variable within a range-based for statement[13]
  • lambdas in unevaluated contexts[14][15]
  • default constructible and assignable stateless lambdas[14][16]
  • allow pack expansions in lambda init-capture[14][17]
  • string literals as template parameters[14][18]
  • removing the need for typename in certain circumstances[19]
  • new standard attributes [[no_unique_address]],[20] [[likely]] and [[unlikely]][21]
  • conditional explicit, allowing the explicit modifier to be contingent on a boolean expression[22]
  • expanded constexpr: virtual functions,[23] union,[24] try and catch,[25] dynamic_cast and typeid,[26] std::pointer_traits[27]
  • immediate functions using the new consteval keyword[28]
  • signed integers are now defined to be represented using two's complement (signed integer overflow remains undefined behavior)[29]
  • a revised memory model[30]
  • various improvements to structured bindings (interaction with lambda captures, static and thread_local storage duration)[31][32]
  • coroutines[33]
  • using on scoped enums[34]
  • constinit keyword[35]

Library

  • ranges (The One Ranges Proposal)[36]
  • std::make_shared and std::allocate_shared for arrays[37]
  • atomic smart pointers (such as std::atomic<shared_ptr<T>> and std::atomic<weak_ptr<T>>)[38]
  • std::to_address to convert a pointer to a raw pointer[39]
  • calendar and time-zone additions to <chrono>[40]
  • std::span, providing a view to a contiguous array (analogous to std::string_view but span can mutate the referenced sequence)[41]
  • <version> header[42]
  • std::bit_cast<> for type casting of object representations, with less verbosity than memcpy() and more ability to exploit compiler internals[43]
  • feature test macros[44]
  • various constexpr library bits[45]
  • smart pointer creation with default initialization[46]
  • std::map::contains method[47]
  • bit operations, such as leading/trailing zero/one count[48], and log2 operations[49][50][51]

Deprecation

  • Use of comma operator in subscript expressions has been deprecated[52]
  • (most of) volatile has been deprecated[53]

New (and changed) keywords

Many new keywords added (and the new "spaceship operator", operator <=>), such as concept, constinit,[35] consteval, co_await, co_return, co_yield, requires (plus changed meaning for export), and char8_t.[54] And explicit can take an expression since C++20.[55] Most of the uses of the volatile keyword have been deprecated.[53]

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]][56]

History of changes

Changes applied to the C++20 working draft in July 2017 (Toronto) include:[57]

  • concepts
  • 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:[58][59]

  • three-way comparison 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<shared_ptr<T>> and std::atomic<weak_ptr<T>>)
  • std::to_address to convert a pointer to a raw pointer

Changes applied to the C++20 working draft in March 2018 (Jacksonville) include:[60]

  • removing the need for typename in certain circumstances[61]
  • new standard attributes [[no_unique_address]],[62] [[likely]] and [[unlikely]][63]
  • calendar and time-zone additions to <chrono>[64]
  • std::span, providing a view to a contiguous array (analogous to std::string_view but span can mutate the referenced sequence)[65]
  • <version> header[66]

Changes applied to the C++20 working draft in the summer meeting in June 2018 (Rapperswil) include:[67]

  • contracts deferred to a later standard[68]
  • feature test macros[69]
  • bit-casting of object representations, with less verbosity than memcpy() and more ability to exploit compiler internals[70]
  • conditional explicit, allowing the explicit modifier to be contingent on a boolean expression[71]
  • constexpr virtual functions[72]

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[73]
  • immediate functions using the new consteval keyword[74]
  • signed integers are now defined to be represented using two's complement (signed integer overflow remains undefined behavior)[75]
  • refinements of the contracts facility (access control in contract conditions)[76] (see list of features deferred to a later standard)
  • a revised memory model[77]
  • Smart pointer creation with default initialization[78]

Changes applied to the C++20 working draft in the winter meeting in February 2019 (Kona) include:[79][80]

  • coroutines[81]  already experimentally supported in Clang 5[82]
  • modules[83]  experimentally supported in Clang 5[84] and Visual Studio 2015 Update 1[85] as well as GCC[86]
  • various improvements to structured bindings (interaction with lambda captures, static and thread_local storage duration)[87][88]

Changes applied to the C++20 working draft in the summer meeting in July 2019 (Cologne) include:[89][90][91]

  • contracts have been removed (see list of features deferred to a later standard)[92]
  • use of comma operator in subscript expressions has been deprecated[93]
  • constexpr additions (trivial default initialization,[94] unevaluated inline-assembly[95])
  • using scoped enums[96]
  • various changes to the spaceship operator[97][98]
  • DR: minor changes to modules[99]
  • constinit keyword
  • changes to concepts (removal of -> Type return-type-requirements[100])
  • (most of) volatile has been deprecated[53]
  • DR: [[nodiscard]] effects on constructors[101]
  • The new standard library concepts will not use PascalCase (rather standard_case, as the rest of the standard library)[102]
  • text formatting[103][104] (chrono integration,[105] corner case fixes[106])
  • bit operations[107]
  • constexpr INVOKE[108]
  • math constants[109]
  • consistency additions to atomics (std::atomic_ref<T>,[110] std::atomic<std::shared_ptr<T>>[111])
  • add the <=> operator to the standard library[112]
  • header units for the standard library[113]
  • synchronization facilities[114] (merged from: Efficient atomic waiting and semaphores,[115] latches and barriers,[116] Improving atomic_flag,[117] Don't Make C++ Unimplementable On Small CPUs[118])
  • std::source_location[119]
  • constexpr containers (std::string,[120] std::vector[121])
  • std::stop_token and joining thread (std::jthread)[122]

Changes applied during the NB comment resolution in the fall meeting in November 2019 (Belfast) include:[123][124][125]

  • 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==.[126] This allows also for array members in class-type NTTP.
  • Floating-point types,[127] 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[128]
  • std::spans typedef was changed from index_type to size_type to be consistent with the rest of the standard library[129]
  • 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,[130] P1391R4: Range constructor for std::string_view (constructor from iterator-pair of characters),[131] P1394R4: Range constructor for std::span<ref>,[132] P1870R1: forwarding-range<T> is too subtle[133])
  • Initialization for std::atomic<T> has been changed to make it work with default and list initialization,[134] 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[135]

Features published as Technical Specifications

Features deferred to a later standard

  • Contracts  a new study group (SG21) has been formed to work on a new proposal[140]
  • Reflection[141][142]
  • Metaclasses[143]
  • Executors[144]
  • Networking extensions,[145][146] including async, basic I/O services, timers, buffers and buffer-oriented streams, sockets, and Internet protocols (blocked by executors)
  • Properties[147]
  • Extended futures[148]
gollark: Yes, trivially, via encoding of bytes into unary.
gollark: Yes, you said.
gollark: I could buy very moderately good GPUs for that much money.
gollark: Apparently it's something like £700.
gollark: If I was a pizza salesman - which I am not - then in order to move around bulk pizzas.

See also

References

  1. "The next standard after C++17 will be C++20"., by Herb Sutter
  2. Sutter, Herb (2019-10-01). "P1000R3: C++ IS schedule" (PDF). Retrieved 2020-02-13.
  3. Dusíková, Hana (2019-11-06). "N4817: 2020 Prague Meeting Invitation and Information" (PDF). Retrieved 2020-02-13.
  4. "Current Status : Standard C++". Retrieved 2020-07-16.
  5. "Why does the C++ standard ship every three years?".
  6. "P0592R0: To boldly suggest an overall plan for C++20".
  7. "P0606R0: Concepts Are Ready" (PDF).
  8. "P1141R1 - Yet another approach for constrained declarations".
  9. "N4720: Working Draft, Extensions to C++ for Modules" (PDF).
  10. Tim Shen; Richard Smith. "Designated Initialization Wording".
  11. Thomas Köppe. "Allow lambda capture [=, this]".
  12. "Familiar template syntax for generic lambdas".
  13. "Range-based for statements with initializer".
  14. "Trip Report: C++ Standards Meeting in Albuquerque, November 2017". There's Waldo!. 2017-11-20. Retrieved 2017-12-11.
  15. "Wording for lambdas in unevaluated contexts" (PDF).
  16. "Default constructible and assignable stateless lambdas" (PDF).
  17. "Pack expansion in lambda init-capture". www.open-std.org. Retrieved 2017-12-11.
  18. "String literals as non-type template parameters" (PDF).
  19. Nina Ranns; Daveed Vandevoorde. "Down with typename!".
  20. "Language support for empty objects".
  21. "Proposed wording for likely and unlikely attributes (Revision 5)".
  22. "explicit(bool)". www.open-std.org. Retrieved 2018-11-13.
  23. "Allowing Virtual Function Calls in Constant Expressions". www.open-std.org. Retrieved 2019-03-11.
  24. "P1330R0 - Changing the active member of a union inside constexpr".
  25. "P1002R0 - Try-catch blocks in constexpr functions" (PDF).
  26. "P1327R0 - Allowing dynamic_cast, polymorphic typeid in Constant Expressions".
  27. "P1006R1 - Constexpr in std::pointer_traits" (PDF).
  28. "P1073R2 - Immediate functions".
  29. "P1236R0: Alternative Wording for P0907R4 Signed Integers are Two's Complement".
  30. "P0668R4: Revising the C++ memory model".
  31. "P1091R1: Extending structured bindings to be more like variable declarations". www.open-std.org. Retrieved 2019-02-24.
  32. "P1091R2: Extending structured bindings to be more like variable declarations". www.open-std.org. Retrieved 2019-02-24.
  33. "N4649: Working Draft, Technical Specification on C++ Extensions for Coroutines" (PDF).
  34. "P1099R5: Using Enum". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  35. "P1143R2: Adding the constinit keyword". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  36. "P0896R3" (PDF).
  37. "Extending make_shared to Support Arrays".
  38. Meredith, Alisdair; Sutter, Herb. "Revising atomic_shared_ptr for C++20". JTC1/SC22/WG21 - The C++ Standards Committee - ISOCPP. ISO. Retrieved 27 December 2018.
  39. "Utility to convert a pointer to a raw pointer".
  40. Howard E. Hinnant; Tomasz Kamiński. "Extending <chrono> to Calendars and Time Zones".
  41. Neil MacIntosh; Stephan T. Lavavej. "span: bounds-safe views for sequences of objects".
  42. Alan Talbot. "<version>".
  43. "Bit-casting object representations". www.open-std.org. Retrieved 2018-11-10.
  44. "Integrating feature-test macros into the C++ WD". www.open-std.org. Retrieved 2018-11-10.
  45. "P1032R1 - Misc constexpr bits".
  46. "Smart pointer creation with default initialization".
  47. "std::map::contains - cppreference.com". en.cppreference.com. Retrieved 2020-05-12.
  48. "P0553R4: Bit operations". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  49. "P0556R3: Integral power-of-2 operations". www.open-std.org. 2018-06-06. Retrieved 2020-08-08.
  50. "P1355R2 Exposing a narrow contract for ceil2". www.open-std.org. 2019-06-11. Retrieved 2020-08-08.
  51. "On the names of low-level bit manipulation functions" (PDF). www.open-std.org. 2020-02-11. Retrieved 2020-08-08.
  52. "P1161R2: Deprecate uses of the comma operator in subscripting expressions". www.open-std.org. Retrieved 2019-07-20.
  53. "P1152R4: Deprecating volatile". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  54. "C++ keywords - cppreference.com". en.cppreference.com. Retrieved 2019-08-04.
  55. "explicit specifier - cppreference.com". en.cppreference.com. Retrieved 2019-08-04.
  56. "attribute specifier sequence(since C++11) - cppreference.com". en.cppreference.com. Retrieved 2019-08-04.
  57. Herb Sutter. "Trip report: Summer ISO C++ standards meeting (Toronto)".
  58. Herb Sutter. "Trip report: Fall ISO C++ standards meeting (Albuquerque)".
  59. Smith, Richard; Perchik, Dawn; Köppe, Thomas. "N4714 Editors' Report -- Programming Languages -- C++". C++ standards drafts. GitHub. Retrieved 27 December 2018.
  60. Botond Ballo. "Trip Report: C++ Standards Meeting in Jacksonville, March 2018".
  61. Nina Ranns; Daveed Vandevoorde. "Down with typename!".
  62. "Language support for empty objects".
  63. "Proposed wording for likely and unlikely attributes (Revision 5)".
  64. Howard E. Hinnant; Tomasz Kamiński. "Extending <chrono> to Calendars and Time Zones".
  65. Neil MacIntosh; Stephan T. Lavavej. "span: bounds-safe views for sequences of objects".
  66. Alan Talbot. "<version>".
  67. Herb Sutter. "Trip report: Summer ISO C++ standards meeting (Rapperswil)".
  68. "Support for contract based programming in C++". www.open-std.org. Retrieved 2018-11-10.
  69. "Integrating feature-test macros into the C++ WD". www.open-std.org. Retrieved 2018-11-10.
  70. "Bit-casting object representations". www.open-std.org. Retrieved 2018-11-10.
  71. "explicit(bool)". www.open-std.org. Retrieved 2018-11-13.
  72. "Allowing Virtual Function Calls in Constant Expressions". www.open-std.org. Retrieved 2019-03-11.
  73. "P1032R1 - Misc constexpr bits".
  74. "P1073R2 - Immediate functions".
  75. "P1236R0: Alternative Wording for P0907R4 Signed Integers are Two's Complement".
  76. "P1289R0 - Access control in contract conditions" (PDF).
  77. "P0668R4: Revising the C++ memory model".
  78. "Smart pointer creation with default initialization".
  79. "r/cpp - 2019-02 Kona ISO C++ Committee Trip Report (C++20 design is complete; Modules in C++20; Coroutines in C++20; Reflection TS v1 published; work begins on a C++ Ecosystem Technical Report)". reddit. Retrieved 2019-02-24.
  80. "Trip report: Winter ISO C++ standards meeting (Kona)". Sutter’s Mill. 2019-02-23. Retrieved 2019-02-24.
  81. "N4649: Working Draft, Technical Specification on C++ Extensions for Coroutines" (PDF).
  82. "Clang 5 Release Notes on coroutines".
  83. "N4720: Working Draft, Extensions to C++ for Modules" (PDF).
  84. "Clang 5 documentation on Modules".
  85. "C++ Modules in VS 2015 Update 1".
  86. "cxx-modules - GCC Wiki". gcc.gnu.org. Retrieved 2019-02-24.
  87. "P1091R1: Extending structured bindings to be more like variable declarations". www.open-std.org. Retrieved 2019-02-24.
  88. "P1091R2: Extending structured bindings to be more like variable declarations". www.open-std.org. Retrieved 2019-02-24.
  89. "r/cpp - 2019-07 Cologne ISO C++ Committee Trip Report — 🚀 The C++20 Eagle has Landed 🚀 (C++20 Committee Draft shipped; Contracts Moved From C++20 to a Study Group; `std::format` in C++20; C++20 Synchronization Library)". reddit. Retrieved 2019-09-15.
  90. Botond Ballo. "Trip Report: C++ Standards Meeting in Cologne, July 2019".
  91. Sutter, Herb. "Trip report: Summer ISO C++ standards meeting (Cologne)".
  92. Josuttis, Nicolai. "P1823R0: Remove Contracts from C++20" (PDF).
  93. "P1161R2: Deprecate uses of the comma operator in subscripting expressions". www.open-std.org. Retrieved 2019-07-20.
  94. "Permitting trivial default initialization in constexpr contexts" (PDF).
  95. "P1668R1: Enabling Constexpr Intrinsics By Permitting Unevaluated inline-asm in Constexpr Functions". www.open-std.org. Retrieved 2019-07-20.
  96. "P1099R5: Using Enum". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  97. "P1186R3: When do you actually use <=>?". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  98. "P1630R1: Spaceship needs a tune-up". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  99. "P1766R1: Mitigating minor modules maladies". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  100. "P1452R2: On the non-uniform semantics of return-type-requirements". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  101. "P1771R1: nodiscard for constructors" (PDF). www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  102. "P1754R1: Rename concepts to standard_case for C++20, while we still can" (PDF). www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  103. "P0645R10: Text Formatting". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  104. "std::format in C++20". www.zverovich.net. 2019-07-23. Retrieved 2019-09-15.
  105. "P1361R2: Integration of chrono with text formatting" (PDF). www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  106. "P1652R1: Printf corner cases in std::format". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  107. "P0553R4: Bit operations". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  108. "P1965R2: constexpr INVOKE". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  109. "P0631R8: Math Constants" (PDF). www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  110. "P1643R1: Add wait/notify to atomic_ref<T>". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  111. "P1664R0: Add wait/notify to atomic<shared_ptr<T>>". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  112. "P1614R2: The Mothership has Landed - Adding <=> to the Library". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  113. "P1502R1: Standard library header units for C++20". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  114. "P1135R6: The C++20 Synchronization Library". www.open-std.org. 2019-07-20. Retrieved 2019-07-20.
  115. "P0514R4: Efficient concurrent waiting for C++20" (PDF).
  116. "P0666R2: Revised Latches and Barriers for C++20" (PDF).
  117. "P0995R1: Improving atomic_flag".
  118. "P1285R0: Don't Make C++ Unimplementable On Small CPUs".
  119. "P1208R6: Adopt source_location from Library Fundamentals V3 for C++20" (PDF).
  120. "P0980R1: Making std::string constexpr" (PDF).
  121. "P1004R2: Making std::vector constexpr" (PDF).
  122. "P0660R10: Stop Token and Joining Thread" (PDF).
  123. "r/cpp - 2019-11 Belfast ISO C++ Committee Trip Report — Started Processing Feedback on the C++20 Committee Draft; ABI Review Group Formed". reddit. Retrieved 2019-11-09.
  124. Sutter, Herb (2019-11-09). "Trip report: Autumn ISO C++ standards meeting (Belfast)". Sutter’s Mill. Retrieved 2019-11-09.
  125. botondballo (2019-11-15). "Trip Report: C++ Standards Meeting in Belfast, November 2019". There's Waldo!. Retrieved 2019-11-24.
  126. "P1907R0: Inconsistencies with non-type template parameters". www.open-std.org. 2019-10-07. Retrieved 2019-11-09.
  127. "P1714: NTTP are incomplete without float, double, and long double! (Revision 1)". www.open-std.org. 2019-07-19. Retrieved 2019-11-09.
  128. "P1855R=: Make <compare> freestanding". www.open-std.org. 2019-10-05. Retrieved 2019-11-09.
  129. "P1872R0: span should have size_type not index_type" (PDF). www.open-std.org. 2019-09-16. Retrieved 2019-11-09.
  130. "P1456: Move-only views" (PDF). www.open-std.org. 2019-01-25. Retrieved 2019-11-09.
  131. "P1391: Range constructor for std::string_view" (PDF). www.open-std.org. Retrieved 2019-11-09.
  132. "P1394: Range constructor for std::span" (PDF). www.open-std.org. 2019-08-02. Retrieved 2019-11-09.
  133. "P1870R1: forwarding-range<T> is too subtle". www.open-std.org. Retrieved 2019-11-09.
  134. "P0883: Fixing Atomic Initialization" (PDF). www.open-std.org. 2018-06-05. Retrieved 2019-11-09.
  135. "Missing feature-test macros 2018-2019". www.open-std.org. 2019-10-06. Retrieved 2019-11-09.
  136. "C++ Extensions for Parallelism Version 2".
  137. "Task Blocks".
  138. "C++ Extensions for Networking".
  139. "C++ Extensions for Reflection".
  140. Sutter, Herb (2019-07-20). "Trip report: Summer ISO C++ standards meeting (Cologne)". Sutter’s Mill. Retrieved 2019-07-21.
  141. "Reflections on the reflection proposals - Meeting C++". meetingcpp.com. Retrieved 2017-06-30.
  142. "Static reflection". www.open-std.org. Retrieved 2018-11-10.
  143. Herb Sutter. "Metaclasses" (PDF).
  144. "A Unified Executors Proposal for C++". www.open-std.org. Retrieved 2019-02-24.
  145. "N4771: Working Draft, C++ Extensions for Networking" (PDF).
  146. "ISO/IEC TS 19216:2018 Programming Languages -- C++ Extensions for Networking".
  147. "A General Property Customization Mechanism". www.open-std.org. Retrieved 2019-02-24.
  148. "A Unified Futures Proposal for C++".
  • 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
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.