C++20
来自cppreference.com
                    
                                        
                    < cpp
                    
                                                            
                    C++ 标准的下一主要修订版
| 本节未完成 | 
新的语言特性
- 特性测试宏
 - 三路比较运算符 <=> 和 operator==() = default
 - 指派初始化器
 -  范围 
for中的初始化语句和初始化器 - char8_t
 -  
[[no_unique_address]] -  
[[likely]] -  
[[unlikely]] - lambda 初始化捕获中的包展开
 -  移除了在多种上下文语境中,使用 
typename关键字以消除类型歧义的要求 - consteval 、 constinit
 - 更为宽松的 constexpr 要求
 - 规定有符号整数以补码实现
 - 使用圆括号的聚合初始化
 - 协程
 - 模块
 - 限定与概念
 - 缩略函数模板
 - DR :数组 new 可推导数组长度
 
新的库特性
新的头文件
- <concepts>
 - <coroutine>
 - <compare>
 - <version>
 - <source_location>
 - <format>
 - <span>
 - <ranges>
 - <bit>
 - <numbers>
 - <syncstream>
 
线程支持库中:
库特性
- 库特性测试宏
 - 格式化库
 - 日历和时区库
 - std::source_location
 - std::span
 - std::endian
 - 针对数组的 std::make_shared 支持
 - std::remove_cvref
 - std::to_address
 - 浮点类型和 shared_ptr 的原子对象
 - std::barrier 、 std::latch 和 std::counting_semaphore
 - std::jthread 和线程取消类
 - std::osyncstream
 - std::u8string 和其他 char8_t 的使用
 -  
<algorithm>、<utility>、<complex>中设施的 constexpr 化 - std::string::starts_with / ends_with 与 std::string_view::starts_with / ends_with
 - assume_aligned
 - bind_front
 - c8rtomb/mbrtoc8
 - make_obj_using_allocator 等
 - std::make_shared_for_overwrite/std::make_unique_for_overwrite
 - 无序关联容器中的异质查找
 - std::polymoprhic_allocator 的额外成员函数和 std::byte 作为其默认模板实参
 - std::execution::unseq
 - std::midpoint 和 std::lerp
 - std::ssize
 - std::is_bounded_array
 - 范围
 -  统一容器擦除 (
std::erase/std::erase_if) - 数学常数
 
缺陷报告
编译器支持情况
主条目: C++ 编译器支持
C++20 核心语言功能特性
|  C++20 功能特性 | 
 提案 | 
  GCC  | 
  Clang  | 
  MSVC  | 
  Apple Clang  | 
  EDG eccp  | 
  Intel C++  | 
  IBM XLC++  | 
  Sun/Oracle C++  | 
  Embarcadero C++ Builder  | 
  Cray  | 
  Portland Group (PGI)  | 
  Nvidia nvcc  | 
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
 允许 lambda 捕获 [=, this]
 | 
P0409R2 | 8 | 6 | 19.22* | 
 10.0.0*  | 
5.1 | ||||||||
 __VA_OPT__
 | 
 P0306R4 P1042R1  | 
8 (部分)* 10  | 
9 | 19.25* | 
 11.0.3*  | 
5.1 | ||||||||
| 指派初始化器 | P0329R4 | 4.7 (部分)* 8  | 
3.0 (部分)* 10  | 
19.21* | (部分)* | 5.1 | ||||||||
| 泛型 lambda 的模板形参列表 | P0428R2 | 8 | 9 | 19.22* | 
 11.0.0*  | 
5.1 | ||||||||
| 位域的默认成员初始化器 | P0683R1 | 8 | 6 | 19.25* | 
 10.0.0*  | 
5.1 | ||||||||
| 类模板实参推导中的 intializer_list 构造函数 | P0702R1 | 8 | 6 | 19.14* | 是 | 5.0 | ||||||||
| const& 限定的成员指针 | P0704R1 | 8 | 6 | 19.0* | 
 10.0.0*  | 
5.1 | ||||||||
| 概念 | P0734R0 | 6 (仅 TS) 10  | 
10 | 19.23* (部分)* | ||||||||||
| 不求值语境中的 lambda | P0315R4 | 9 | ||||||||||||
| 三路比较运算符 | P0515R3 | 10 | 8 (部分) 10  | 
19.20* | 5.1 | |||||||||
| DR :简化隐式 lambda 捕获 | P0588R1 | 8 | 19.24* | 5.1 | ||||||||||
| 基于范围的 for 的初始化语句 | P0614R1 | 9 | 8 | 19.25* | 
 11.0.0*  | 
6.0 | ||||||||
| 可默认构造与可赋值的无状态 lambda | P0624R2 | 9 | 8 | 19.22* | 
 10.0.1*  | 
5.1 | ||||||||
| 预置复制构造函数与 const 的不匹配 | P0641R2 | 9 | 8 | 19.21* (部分) | 
 10.0.1*  | 
5.1 | ||||||||
| 特化上的访问检查 | P0692R1 | 是 | 8 (部分) | 19.26* | 
 10.0.1* (部分)  | 
5.1 | ||||||||
| ADL 与不可见的函数模板 | P0846R0 | 9 | 9 | 19.21* | 
 11.0.3*  | 
5.1 | ||||||||
 指定 constexpr 函数定义何时为常量求值所需要
 | 
P0859R0 | 5.2 (部分)* 9  | 
8 | |||||||||||
 属性 [[likely]] 与 [[unlikely]]
 | 
P0479R5 | 9 | 19.26* | 5.1 | ||||||||||
 使 typename 更可选
 | 
P0634R3 | 9 | 5.1 | |||||||||||
| Lambda 初始化捕获中的包展开 | P0780R2 | 9 | 9 | 19.22* | 
 11.0.3*  | 
|||||||||
 属性 [[no_unique_address]]
 | 
P0840R2 | 9 | 9 | 
 11.0.3*  | 
5.1 | |||||||||
| DR :放松结构化绑定定制点查找规则 | P0961R1 | 8 | 8 | 19.21* | 
 10.0.1*  | 
5.1 | ||||||||
 DR :放松范围 for 循环定制点查找规则
 | 
P0962R1 | 8 | 5.1 | |||||||||||
| DR :允许到可访问成员的结构化绑定 | P0969R0 | 8 | 8 | 19.21* | 
 10.0.1*  | 
5.1 | ||||||||
| 销毁的 operator delete | P0722R3 | 9 | 6 | 19.27* | 
 10.0.0*  | 
6.1 | ||||||||
| 非类型模板形参中的类类型 | P0732R2 | 9 | 19.26* | |||||||||||
 弃用经由 [=] 隐式捕获 this
 | 
P0806R2 | 9 | 19.22* | 5.1 | ||||||||||
| explicit(bool) | P0892R2 | 9 | 9 | 19.24* | 
 11.0.3*  | 
5.1 | ||||||||
| 集成特性测试宏 | P0941R2 | 5 | 3.4 | 19.15* (部分) 19.20*  | 
是 | 5.0 | ||||||||
| 禁止有用户声明构造函数的聚合体 | P1008R1 | 9 | 8 | 19.20* | 
 10.0.1*  | 
5.1 | ||||||||
| constexpr 虚函数 | P1064R0 | 9 | 9 | 
 11.0.3*  | 
5.1 | |||||||||
| 比较的一致性改进 | P1120R0 | 10 | 8 (部分) 10  | 
19.22* | 
 10.0.1* (部分)  | 
5.1 | ||||||||
 char8_t
 | 
P0482R6 | 9 | 7 | 19.22* | 
 10.0.0*  | 
5.1 | ||||||||
| std::is_constant_evaluated() | P0595R2 | 9 | 9 | 19.25* | 
 11.0.3*  | 
5.1 | 19.1 | |||||||
 constexpr 函数中的 try-catch 块
 | 
P1002R1 | 9 | 8 | 19.25* | 
 10.0.1*  | 
5.1 | ||||||||
| 立即函数 | P1073R3 | 10 (部分)* | 5.1 | |||||||||||
| 嵌套 inline 命名空间 | P1094R2 | 9 | 8 | 
 10.0.1*  | 
5.1 | |||||||||
| 有制约声明的另一种手段 | P1141R2 | 10 | 19.26* (部分) | |||||||||||
| 有符号整数为补码 | P1236R1 | 9 | 9 | 
 11.0.3*  | 
||||||||||
 constexpr dynamic_cast 及多态 typeid
 | 
P1327R1 | 10 | 9 | 
 11.0.3*  | 
5.1 | |||||||||
| 在 constexpr 内更改联合体的活跃成员 | P1330R0 | 9 | 9 | 19.10* | 
 11.0.3*  | 
5.1 | ||||||||
| 协程 | P0912R5 | 10 | 8 (部分) | 19.25* (部分) | 
 10.0.1* (部分)  | 
5.1 | ||||||||
| 聚合体的括号初始化 | P0960R3 | 10 | 5.1 | |||||||||||
| DR : new 表达式中的数组大小推导 | P1009R2 | 10 (C++20模式); 11 | 9 | 
 11.0.3*  | 
5.1 | |||||||||
| 模块 | P1103R3 | 11 (部分) | 8 (部分) | 19.25* (部分) | 
 10.0.1* (部分)  | 
|||||||||
| 更强的 Unicode 要求 |  P1041R4 P1139R2  | 
10 | 是 | 19.0* (P1041R4) 19.26* (P1139R2)  | 
是 | N/A | ||||||||
 <=> != ==
 | 
P1185R2 | 10 | 10 | 19.22* | 5.1 | |||||||||
| DR :拥有不同异常说明的显式默认化函数 | P1286R2 | 10 | 9 | 
 11.0.3*  | 
5.1 | |||||||||
| 结构化绑定的 lambda 捕获与存储类说明符 |  P1091R3 P1381R1  | 
10 | 8 (部分) | 
 10.0.1* (部分)  | 
5.1 | |||||||||
| 容许转换到未知边界数组 | P0388R4 | 10 | 6.0 | |||||||||||
| constexpr 容器操作 | P0784R7 | 10 | 10 | 6.0 | ||||||||||
 弃用 volatile 的某些用法
 | 
P1152R4 | 10 | 10 | 6.0 | ||||||||||
| constinit | P1143R2 | 10 | 10 | |||||||||||
| 弃用下标中的逗号运算符 | P1161R3 | 10 | 9 | 19.25* | 
 11.0.3*  | 
6.0 | ||||||||
 带消息的 [[nodiscard]]
 | 
P1301R4 | 10 | 9 | 19.25* | 
 11.0.3*  | 
6.0 | ||||||||
| constexpr 函数中的平凡默认初始化 | P1331R2 | 10 | 10 | 6.0 | ||||||||||
| constexpr 函数中的不求值汇编声明 | P1668R1 | 10 | 10 | 6.1 | ||||||||||
| using enum | P1099R5 | 11 | 19.24* | |||||||||||
| 对指定的比较类别合成三路比较 | P1186R3 | 10 | 10 | 19.24* | 6.0 | |||||||||
 DR :构造函数的 [[nodiscard]]
 | 
P1771R1 | 10 | 9 | 19.24* | 
 11.0.3*  | 
6.0 | ||||||||
| 别名模板的类模板实参推导 | P1814R0 | 10 | ||||||||||||
| 聚合类的类模板实参推导 | P1816R0 | 10 | ||||||||||||
| DR :更多局部对象与右值引用的隐式移动 | P1825R0 | 11 (C++20模式) | 19.24* | 6.0 | ||||||||||
| 允许默认化按值比较 | P1946R0 | 10 | 19.25* | 6.1 | ||||||||||
 移除 std::weak_equality 与 std::strong_equality
 | 
P1959R0 | 10 | 19.25* | |||||||||||
| 非类型模板形参的不一致 | P1907R1 | 9 | 19.26* | |||||||||||
| DR :伪析构函数终结对象生存期 | P0593R6 | 11 | 11 | |||||||||||
 DR :应认为从 T* 到 bool 的转换为窄化
 | 
P1957R2 | 10* | ||||||||||||
|  C++20 功能特性 | 
 提案 | 
  GCC  | 
  Clang  | 
  MSVC  | 
  Apple Clang  | 
  EDG eccp  | 
  Intel C++  | 
  IBM XLC++  | 
  Sun/Oracle C++  | 
  Embarcadero C++ Builder  | 
  Cray  | 
  Portland Group (PGI)  | 
  Nvidia nvcc  | 
C++20 库功能特性
|  C++20 功能特性 | 
 提案 | 
  GCC libstdc++  | 
  Clang libc++  | 
  Apple Clang  | 
  MSVC 标准库  | 
  Sun/Oracle C++ 标准库  | 
  Embarcadero C++ Builder 标准库  | 
  Cray C++ 标准库  | 
|
|---|---|---|---|---|---|---|---|---|---|
| std::endian | P0463R1 | 8 | 7 | 
 10.0.0*  | 
19.22* | ||||
| 扩展 std::make_shared() 以支持数组 | P0674R1 | 19.27* | |||||||
| 浮点原子类型 | P0020R6 | 10 | 19.22* | ||||||
| 同步缓冲的输出流 | P0053R7 | ||||||||
 <algorithm> 与 <utility> 的 constexpr
 | 
P0202R3 | 10 | 8 (部分) | 
 10.0.1* (部分)  | 
19.26* | ||||
 <complex> 的更多 constexpr
 | 
P0415R1 | 9 | 7 (部分) | 
 10.0.0* (部分)  | 
19.27* | ||||
| 使 std::memory_order 为有作用域枚举 | P0439R0 | 9 | 9 | 
 11.0.3*  | 
19.25* | ||||
| 字符串前缀与后缀检查 | P0457R2 | 9 | 6 | 19.21* | |||||
 operator<=> 的库支持 <compare>
 | 
P0768R1 | 10 | 7 (部分) | 
 10.0.0* (部分)  | 
19.20* (部分) | ||||
| std::remove_cvref | P0550R2 | 9 | 6 | 
 10.0.0*  | 
19.20* | ||||
 标准库中的 [[nodiscard]]
 | 
P0600R1 | 9 | 7 (部分) | 
 10.0.0* (部分)  | 
19.13* (部分) 19.22*  | 
||||
 于数值算法使用 std::move
 | 
P0616R0 | 9 | 19.23* | ||||||
| 转换指针为裸指针的工具 | P0653R2 | 8 | 6 | 是 | 19.22* | ||||
| 原子 std::shared_ptr 与 std::weak_ptr | P0718R2 | 19.27* | |||||||
| std::span | P0122R7 | 10 | 7 | 
 10.0.0*  | 
19.26* | ||||
| 日历与时区 | P0355R7 | 7 (部分) | 
 10.0.0* (部分)  | 
||||||
| <version> | P0754R2 | 9 | 7 | 
 10.0.0*  | 
19.22* | ||||
| 比较无序容器 | P0809R0 | 16.0* | |||||||
| 常量表达式迭代器 (ConstexprIterator) 要求 | P0858R0 | 9 | 19.11* | ||||||
| std::basic_string::reserve() 不应收缩 | P0966R1 | 8 | 
 10.0.1*  | 
19.25* | |||||
| std::atomic_ref | P0019R8 | 10 | |||||||
 关联容器的 contains() 成员函数
 | 
P0458R2 | 9 | 19.21* | ||||||
| DR :逐片构造的受保证复制消除 | P0475R1 | 9 | |||||||
| std::bit_cast() | P0476R2 | 19.27* | |||||||
| 整数的 2 的幂的运算 |  P0556R3 P1956R1  | 
9 (P0556R3) 10 (P1956R1)  | 
19.25* (P0556R3) 19.27* (P1956R1)  | 
||||||
 改进仿 erase 算法的返回值
 | 
P0646R1 | 9 | 10 | 19.21* | |||||
| std::destroying_delete | P0722R3 | 9 | 9 | 
 11.0.3*  | 
19.27* | ||||
| std::is_nothrow_convertible | P0758R1 | 9 | 9 | 
 11.0.3*  | 
19.23* | ||||
 添加 shift 到 <algorithm>
 | 
P0769R2 | 10 | 19.21* | ||||||
 std::swap() 与 swap 相关函数的 constexpr
 | 
P0879R0 | 10 | 19.26* | ||||||
| std::type_identity | P0887R1 | 9 | 8 | 
 10.0.1*  | 
19.21* | ||||
| 概念库 | P0898R3 | 10 | 19.23* | ||||||
 std::array 的 constexpr 比较运算符
 | 
P1023R0 | 10 | 8 | 
 10.0.1*  | 
19.27* | ||||
 std::unwrap_ref_decay 与 std::unwrap_reference
 | 
P0318R1 | 9 | 8 | 
 10.0.1*  | 
19.21* | ||||
| std::bind_front() | P0356R5 | 9 | 19.25* | ||||||
| 不完整类型的 std::reference_wrapper | P0357R3 | 9 | 8 | 
 10.0.1*  | 
19.26* | ||||
| 修正 operator>>(basic_istream&, CharT*) | P0487R1 | 8 | 
 10.0.1*  | 
19.23* | |||||
 char8_t 的库支持
 | 
P0482R6 | 9 | 19.22* | ||||||
| 实现使用分配器构造的工具函数 | P0591R4 | 9 | |||||||
| DR : std::variant 与 std::optional 应传播复制/移动平凡性 | P0602R4 | 8.3 | 8 | 
 10.0.1*  | 
19.11* | ||||
| 理智的 std::variant 转换构造函数 | P0608R3 | 10 | 9 | 
 11.0.3*  | 
|||||
 std::function 的移动构造函数应为 noexcept
 | 
P0771R1 | 7.2 | 6 | 是 | 19.22* | ||||
| 一个范围提案 | P0896R4 | 10 | |||||||
| 无序容器的异质查找 |  P0919R3 P1690R1  | 
19.23* (P0919R3) 19.25* (P1690R1)  | 
|||||||
 <chrono> zero() 、 min() 及 max() 应为 noexcept
 | 
P0972R0 | 9 | 8 | 
 10.0.1*  | 
19.14* | ||||
 std::pointer_traits 中的 constexpr
 | 
P1006R1 | 9 | 8 | 
 10.0.1*  | 
19.26* | ||||
| std::assume_aligned() | P1007R3 | 9 | |||||||
 移除 std::span 的比较运算符
 | 
P1085R2 | 10 | 8 | 
 10.0.1*  | 
19.26* | ||||
| 使 operator+(basic_string) 的有状态分配器传播更加一致 | P1165R1 | 10 | 19.26* | ||||||
| 一致容器擦除 |  P1209R0 P1115R3  | 
9 (P1209R0) 10 (P1115R3)  | 
8 (P1209R0)  11 (P1115R3)  | 
 10.0.1* (P1209R0)  | 
19.25* (P1209R0) 19.27* (P1115R3)  | 
||||
| std::lerp() 与 std::midpoint() | P0811R3 | 9 | 9 | 
 11.0.3*  | 
19.23* (部分) | ||||
 std::span 的实用性增强
 | 
P1024R3 | 10 | 9 | 
 11.0.3*  | 
19.26* | ||||
| DR :使 create_directory() 自发 | P1164R1 | 8.3 | 19.20* | ||||||
 std::ssize() 与 std::span 的无符号长度
 | 
P1227R2 | 10 | 9 | 
 11.0.3*  | 
19.25* | ||||
| 有界及无界数组特征 | P1357R1 | 9 | 9 | 
 11.0.3*  | 
|||||
| std::to_array() | P0325R4 | 10 | 10 | 19.25* | |||||
| std::basic_stringbuf 缓冲的有效访问 | P0408R7 | ||||||||
| 布局兼容性与指针可互转换性特征 | P0466R5 | ||||||||
| 位操作 | P0553R4 | 9 | 9 | 
 11.0.3*  | 
19.25* | ||||
 数学常数 <numbers>
 | 
P0631R8 | 10 | 19.25* | ||||||
| 文本格式化 | P0645R10 | ||||||||
| std::stop_token 与 std::jthread | P0660R10 | 10 | |||||||
| constexpr std::allocator 及相关工具 | P0784R7 | 10 | |||||||
| constexpr std::string | P0980R1 | ||||||||
| constexpr std::vector | P1004R2 | ||||||||
| 输入范围适配器 | P1035R7 | 10 | |||||||
| constexpr std::invoke() 及相关工具 | P1065R2 | 10 | |||||||
| 原子等待与提醒、 std::counting_semaphore 、 std::latch 及 std::barrier | P1135R6 | ||||||||
| std::source_location | P1208R6 | 7 (仅 TS) | |||||||
 添加 <=> 到标准库
 | 
P1614R2 | 10 | |||||||
| std::atomic 与 std::atomic_flag 的 constexpr 默认构造函数 | P0883R2 | 19.26* | |||||||
| 数值算法的 constexpr | P1645R1 | 10 | 19.26* | ||||||
| 安全整数比较 | P0586R2 | 10 | 19.27* | ||||||
|  C++20 功能特性 | 
 提案 | 
  GCC libstdc++  | 
  Clang libc++  | 
  Apple Clang  | 
  MSVC 标准库  | 
  Sun/Oracle C++ 标准库  | 
  Embarcadero C++ Builder 标准库  | 
  Cray C++ 标准库  | 
* - 在版本号上停留可以查看注记