C++23简介

何谓 C++23

2023 年 2 月,国际标准化组织(ISO)正式通过了 C++ 的新版本——C++23。

C++23 的新增改进

为方便查阅,下面列出 C++23 引入的主要变更。此列表并非穷尽,仅用于凸显关键亮点:

  • constexpr <cmath>(例如 std::abs())与 <cstdlib>(参见《关系运算符与浮点比较》章节)。
  • constexpr std::unique_ptr(暂无章节)。
  • 显式对象形参(explicit this parameter)(暂无课程)。
  • 通过 <stdfloat> 提供的定长浮点类型(暂无课程)。
  • 格式化输出函数 std::printstd::println(暂无课程)。
  • std::size_t 及其对应有符号类型的字面量后缀(参见《字面量》章节)。
  • 多维下标运算符 operator[](《多维 std::array》章节章节中提及)。
  • 多维视图 std::mdspan(《多维 std::array》)。
  • 预处理器指令 #elifdef#elifndef(暂无课程)。
  • 预处理器指令 #warning(暂无课程)。
  • 堆栈回溯库(Stacktrace library)(暂无课程)。
  • 标准库模块 stdstd.compat(暂无课程)。
  • 静态 operator()operator[](暂无课程)。
  • std::bitset 现已完全 constexpr。
  • std::expected(暂无课程)。
  • std::ranges 算法 starts_withends_withcontains(暂无课程)。
  • std::string::containsstd::string_view::contains(暂无课程)。
  • std::to_underlying,用于获取枚举的底层类型(参见《作用域枚举(enum class)》章节)。
  • std::unreachable()(暂无课程)。
  • 在常量表达式中使用未知指针与引用(参见 课程17.2《std::array 长度与索引》)。

关注公众号,回复"cpp-tutorial"

可领取价值199元的C++学习资料

公众号二维码

扫描上方二维码或搜索"cpp-tutorial"