何谓 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::print
与std::println
(暂无课程)。 std::size_t
及其对应有符号类型的字面量后缀(参见《字面量》章节)。- 多维下标运算符
operator[]
(《多维 std::array》章节章节中提及)。 - 多维视图
std::mdspan
(《多维 std::array》)。 - 预处理器指令
#elifdef
与#elifndef
(暂无课程)。 - 预处理器指令
#warning
(暂无课程)。 - 堆栈回溯库(Stacktrace library)(暂无课程)。
- 标准库模块
std
与std.compat
(暂无课程)。 - 静态
operator()
与operator[]
(暂无课程)。 std::bitset
现已完全 constexpr。std::expected
(暂无课程)。std::ranges
算法starts_with
、ends_with
、contains
(暂无课程)。std::string::contains
与std::string_view::contains
(暂无课程)。std::to_underlying
,用于获取枚举的底层类型(参见《作用域枚举(enum class)》章节)。std::unreachable()
(暂无课程)。- 在常量表达式中使用未知指针与引用(参见 课程17.2《std::array 长度与索引》)。