Loading

C++20更新日志

译自。在C++20标准发布后,英文终稿大概会在ISO网站上公开。

  • 新增概念(concepts)、requires子句(requires-clause)、requires表达式(requires-expression)
  • 新增协程(coroutines),包括co_yieldco_awaitco_return关键字和<coroutines>头文件
  • 新增模块(modules)、导入声明(import-declaration)、导出声明(export-declaration)
  • 新增三向比较(three-way comparison)、默认比较(defaulted comparisons)、比较表达式自动重写、<compare>头文件
  • 新增指派初始化器(designated initializers)
  • 支持类类型(class types)和浮点类型(floating-point types)作为非类型模板形参(non-type template parameter)的类型
  • 新的属性(attributes)[[no_unique_address]][[likely]][[unlikely]]
  • 支持在[[nodiscard]]中可选地使用字符串
  • 支持用constinit关键字要求常量初始化(constant initialization)
  • 支持用consteval关键字要求常量求值(constant evaluation)
  • 扩展常量求值支持,包括
    • 内存分配及去分配
    • 虚函数调用
    • dynamic_casttypeid
    • 切换union的活跃成员
    • 未初始化的变量
  • 支持constexpr函数中包含catch异常处理和内联汇编(asm-declaration),只要它们不在常量求值中执行
  • 支持销毁解分配函数(destroying operator delete)
  • 新增using enum声明
  • 新增char8_t类型
  • 保证char16_tchar32_t字面量是UTF-16和UTF-32编码
  • 支持range-based for中的初始化语句
  • 支持位域(bit-fields)的默认初始化器(default member initializers)
  • 支持用括号的聚合类型初始化(aggregate initialization)
  • 扩展lambda表达式支持,包括
    • generic lambda的显式模板头部(template-head)
    • 无状态闭包类型的默认构造和赋值
    • 在不求值表达式(unevaluated operands)中使用lambda表达式
    • 初始化捕获(init-capture)作为包展开(pack expansion)
  • 支持new表达式(new-expression)中的数组长度推断
  • 泛化结构化绑定(structured binding)支持
  • 支持inline命名空间出现在嵌套命名空间定义(nested namespace definitions)中
  • 支持条件性explicit(conditionally-explicit)成员函数
  • 扩展类模板参数推导(class template argument deduction)支持,以包含聚合类型初始化和别名模板
  • 减少需要typename的场合
  • 支持利用参数依赖查找(argument-dependent name lookup)调用未声明的带模板实参的模板名(template-id)
  • 放宽模板特化声明(template specialization declarations)中的访问权限检查(access checking)规则
  • 修订内存模型(memory model)
  • 扩展允许return和throw中的变量被隐式移动(implicitly moved)的情况
  • 扩展变参宏(variadic macros)支持,利用__VA_OPT__
  • 功能特性测试宏(feature test macros)和<version>头文件
  • 限制标准库函数和函数模板的有效用法
  • 新增范围(ranges)和<concepts><ranges>头文件
  • 新增日历(calendar)和时区(time zone)支持
  • 新增文本格式化库(text formatting library)和<format>头文件
  • 新增线程同步设施(synchronization facilities)用于等待(waiting)、唤醒(notifications)、信号量(semaphores)、闭锁(latches)、栅栏(barriers),和<barrier><latch><semaphore>头文件
  • 新增数学常量库(mathematical constants library)和<numbers>头文件
  • 支持表示源码信息(source locations)和<source_location>头文件
  • 新增span视图(view)和<span>头文件
  • 新增自动合并的线程类(joining thread class)和<stop_token>头文件
  • 扩展原子类型和操作(atomic types and operations),包括
    • 新的类模板atomic_ref
    • 新的原子浮点类型
    • 新的原子智能指针类型
    • 支持有填充位(paddings)的类型的比较并交换操作(compare-and-exchange operations)
    • memory_order转换为有作用域枚举(scoped enumeration)
  • 新增unsequenced执行策略(execution policy)
  • 新的标准库工具函数、类型、模板,包括
    • 新的类型特征(type traits)is_bounded_arrayis_corresponding_memberis_layout_compatibleis_nothrow_convertibleis_pointer_interconvertible_base_ofis_pointer_interconvertible_with_classis_unbounded_array
    • 新的变换特征(transformation traits)remove_cvreftype_identityunwrap_ref_decayunwrap_reference
    • 新的标准库原语函数(standard library primitive functions)assume_alignedis_constant_evaluated
    • 新的用于容器的非成员函数(free functions)eraseerase_if
    • 用于使用分配器构造(uses-allocator construction)的工具
    • 函数模板to_address
    • 函数模板bind_front
    • 函数模板to_array
  • make_shared数组支持
  • 支持用默认初始化(default initialization)分配shared_ptrunique_ptr管理的对象
  • 新增位操作库(bit manipulation library)和<bit>头文件
  • 新增同步缓冲区输出流(synchronized buffered output stream)和<syncstream>头文件
  • 新增shift算法
  • 新增midpointlerp数学函数
  • 标准库使用[[nodiscard]]属性
  • 支持无序容器(unordered containers)的异构查找(heterogeneous lookup)
  • 支持关联容器(associative containers)的元素存在性检测(element existence detection)
  • 改变listforward_listremoveremove_ifunique成员函数以返回被删除的元素的数量
  • 新增stringstring_viewstarts_withends_with成员函数
  • 支持在<numeric>算法中利用移动语义(move semantics)
  • 支持高效地访问basic_stringbuf的缓冲区
  • 扩展标准库的常量表达式求值支持,包括更多的算法、工具和类型,如pairtuplevectorstring
  • 删除已弃用的特性
posted @ 2020-03-15 17:58  alphacode  阅读(246)  评论(0)    收藏  举报