Skip to content

Commit 5afb15e

Browse files
committed
book: cover remaining minor C++23 language improvements
Add a 11.1 subsection on smaller C++23 language features: #elifdef/ #elifndef/#warning, named universal character escapes, extended floating-point types (<stdfloat>), and further constexpr relaxations. Refs #317
1 parent 53741bc commit 5afb15e

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

book/en-us/11-cpp23.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ int divide_by(int x) {
8686
}
8787
```
8888

89+
### Other small language improvements
90+
91+
C++23 also includes several smaller language improvements:
92+
93+
- **Preprocessor directives**: added `#elifdef` / `#elifndef` (shorthands for `#elif defined` / `#elif !defined`) and `#warning` for emitting a diagnostic on purpose.
94+
- **Named universal character escapes**: a character can be written by its Unicode name, e.g. `"\N{GREEK SMALL LETTER ALPHA}"`, which is more readable than memorizing code points.
95+
- **Extended floating-point types**: `<stdfloat>` introduces fixed-width floating-point types such as `std::float16_t`, `std::float32_t`, `std::float64_t`, and `std::bfloat16_t` (their availability likewise depends on the platform and standard-library implementation).
96+
- **Further `constexpr` relaxations**: constant evaluation now permits `goto` and labeled statements, as well as declaring (but not using during constant evaluation) variables of non-literal type and `static` variables.
97+
8998
## 11.2 The standard library
9099

91100
### `std::expected`

book/zh-cn/11-cpp23.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ int divide_by(int x) {
8686
}
8787
```
8888

89+
### 其他语言层面的小改进
90+
91+
C++23 还包含若干较小的语言改进:
92+
93+
- **预处理指令**:新增了 `#elifdef` / `#elifndef`(即 `#elif defined` / `#elif !defined` 的简写)以及用于主动产生诊断信息的 `#warning`
94+
- **命名的通用字符转义**:可以用字符的 Unicode 名称来书写字符,例如 `"\N{GREEK SMALL LETTER ALPHA}"`,比记忆码位更直观。
95+
- **扩展浮点类型**:在 `<stdfloat>` 中引入了 `std::float16_t``std::float32_t``std::float64_t``std::bfloat16_t` 等定宽浮点类型(其可用性同样取决于平台与标准库实现)。
96+
- **`constexpr` 的进一步放宽**:允许在常量求值中使用 `goto`、带标签的语句,以及声明(但不在常量求值期间使用)非字面类型的变量与 `static` 变量等。
97+
8998
## 11.2 标准库
9099

91100
### `std::expected`

0 commit comments

Comments
 (0)