Skip to content

Commit f5c82c6

Browse files
committed
book: since markers for Chapters 6, 7, 9 + fix stale C++20 nav text
Add 'since C++NN' markers to the regex, concurrency, and misc-features sections, and drop the leftover 'Outlook/展望' wording from the Chapter 9 -> Chapter 10 navigation link.
1 parent 82ebebb commit f5c82c6

6 files changed

Lines changed: 50 additions & 2 deletions

File tree

book/en-us/06-regex.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ With these two tables, we can usually read almost all regular expressions.
6565

6666
## 6.2 `std::regex` and Its Related
6767

68+
*(since C++11)*
69+
6870
The most common way to match string content is to use regular expressions. Unfortunately, in traditional C++, regular expressions have not been supported by the language level, and are not included in the standard library. C++ is a high-performance language. In the development of background services, the use of regular expressions is also used when judging URL resource links. The most mature and common practice in the industry.
6971

7072
The general solution is to use the regular expression library of `boost`. C++11 officially incorporates the processing of regular expressions into the standard library, providing standard support from the language level and no longer relying on third parties.

book/en-us/07-thread.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ order: 7
1010

1111
## 7.1 Basic of Parallelism
1212

13+
*(since C++11)*
14+
1315
`std::thread` is used to create an execution thread instance, so it is the basis for all concurrent programming. It needs to include the `<thread>` header file when using it.
1416
It provides a number of basic thread operations, such as `get_id()` to get the thread ID of the thread being created, use `join()` to join a thread, etc., for example:
1517

@@ -28,6 +30,8 @@ int main() {
2830

2931
## 7.2 Mutex and Critical Section
3032

33+
*(since C++11)*
34+
3135
We have already learned the basics of concurrency technology in the operating system, or the database, and `mutex` is one of the cores.
3236
C++11 introduces a class related to `mutex`, with all related functions in the `<mutex>` header file.
3337

@@ -117,6 +121,8 @@ int main() {
117121

118122
## 7.3 Future
119123

124+
*(since C++11)*
125+
120126
The Future is represented by `std::future`, which provides a way to access the results of asynchronous operations. This sentence is very difficult to understand.
121127
To understand this feature, we need to understand the multi-threaded behavior before C++11.
122128

@@ -157,6 +163,8 @@ After encapsulating the target to be called, you can use `get_future()` to get a
157163

158164
## 7.4 Condition Variable
159165

166+
*(since C++11)*
167+
160168
The condition variable `std::condition_variable` was born to solve the deadlock and was introduced when the mutex operation was not enough.
161169
For example, a thread may need to wait for a condition to be true to continue execution.
162170
A dead wait loop can cause all other threads to fail to enter the critical section so that when the condition is true, a deadlock occurs.
@@ -229,6 +237,8 @@ We simply can't expect multiple consumers to be able to produce content in a par
229237

230238
## 7.5 Atomic Operation and Memory Model
231239

240+
*(since C++11)*
241+
232242
Careful readers may be tempted by the fact that the example of the producer-consumer model in the previous section may have compiler optimizations that cause program errors.
233243
For example, the compiler may have optimizations for the variable `notified`, such as the value of a register.
234244
As a result, the consumer thread can never observe the change of this value. This is a good question. To explain this problem, we need to further discuss the concept of the memory model introduced from C++11. Let's first look at a question. What is the output of the following code?

book/en-us/09-others.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ order: 9
1010

1111
## 9.1 New Type
1212

13+
*(since C++11)*
14+
1315
### `long long int`
1416

1517
`long long int` is not the first to be introduced in C++11.
@@ -20,6 +22,8 @@ specifying a `long long int` type with at least 64 bits.
2022

2123
## 9.2 `noexcept` and Its Operations
2224

25+
*(since C++11)*
26+
2327
One of the big advantages of C++ over C is that
2428
C++ itself defines a complete set of exception handling mechanisms.
2529
However, before C++11, almost no one used to write an exception declaration expression after the function name.
@@ -104,6 +108,8 @@ exception captured, from non_block_throw()
104108

105109
## 9.3 Literal
106110

111+
*(since C++11)*
112+
107113
### Raw String Literal
108114

109115
In traditional C++, it is very painful to write a string full of
@@ -159,6 +165,8 @@ Custom literals support four literals:
159165

160166
## 9.4 Memory Alignment
161167

168+
*(since C++11)*
169+
162170
C++ 11 introduces two new keywords, `alignof` and `alignas`, to support control of memory alignment.
163171
The `alignof` keyword can get a platform-dependent value of type `std::size_t` to query the alignment of the platform.
164172
Of course, we are sometimes not satisfied with this, and even want to customize the alignment of the structure. Similarly, C++ 11 introduces `alignas`.
@@ -207,6 +215,8 @@ delete p;
207215

208216
## 9.5 Type punning and `std::bit_cast`
209217

218+
*(since C++20)*
219+
210220
"Type punning" means reinterpreting the same memory as a different type, common in low-level code (e.g. reading the bit pattern of a floating-point number). Many people reach for `reinterpret_cast` through a pointer or reference:
211221

212222
```cpp
@@ -233,6 +243,8 @@ float back = std::bit_cast<float>(bits);
233243

234244
## 9.6 Mathematical special functions
235245

246+
*(since C++17)*
247+
236248
C++17 added a set of mathematical special functions to `<cmath>` — such as `std::riemann_zeta`, `std::beta`, `std::assoc_legendre`, and `std::cyl_bessel_j` — useful in scientific computing and machine-learning related domains:
237249

238250
```cpp
@@ -250,7 +262,7 @@ have not yet been introduced. `noexcept` is the most important feature.
250262
One of its features is to prevent the spread of anomalies,
251263
effective Let the compiler optimize our code to the maximum extent possible.
252264

253-
[Table of Content](./toc.md) | [Previous Chapter](./08-filesystem.md) | [Next Chapter: Outlook: Introduction of C++20](./10-cpp20.md)
265+
[Table of Content](./toc.md) | [Previous Chapter](./08-filesystem.md) | [Next Chapter: C++20](./10-cpp20.md)
254266

255267
## Licenses
256268

book/zh-cn/06-regex.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ order: 6
6262

6363
## 6.2 std::regex 及其相关
6464

65+
*(C++11)*
66+
6567
对字符串内容进行匹配的最常见手段就是使用正则表达式。
6668
可惜在传统 C++ 中正则表达式一直没有得到语言层面的支持,没有纳入标准库,
6769
而 C++ 作为一门高性能语言,在后台服务的开发中,对 URL 资源链接进行判断时,

book/zh-cn/07-thread.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ order: 7
1010

1111
## 7.1 并行基础
1212

13+
*(C++11)*
14+
1315
`std::thread` 用于创建一个执行的线程实例,所以它是一切并发编程的基础,使用时需要包含 `<thread>` 头文件,
1416
它提供了很多基本的线程操作,例如 `get_id()` 来获取所创建线程的线程 ID,使用 `join()` 来等待一个线程结束(与该线程汇合)等等,例如:
1517

@@ -28,6 +30,8 @@ int main() {
2830

2931
## 7.2 互斥量与临界区
3032

33+
*(C++11)*
34+
3135
我们在操作系统、亦或是数据库的相关知识中已经了解过了有关并发技术的基本知识,`mutex` 就是其中的核心之一。
3236
C++11 引入了 `mutex` 相关的类,其所有相关的函数都放在 `<mutex>` 头文件中。
3337

@@ -118,6 +122,8 @@ int main() {
118122

119123
## 7.3 期物
120124

125+
*(C++11)*
126+
121127
期物(Future)表现为 `std::future`,它提供了一个访问异步操作结果的途径,这句话很不好理解。
122128
为了理解这个特性,我们需要先理解一下在 C++11 之前的多线程行为。
123129

@@ -160,6 +166,8 @@ int main() {
160166

161167
## 7.4 条件变量
162168

169+
*(C++11)*
170+
163171
条件变量 `std::condition_variable` 是为了解决死锁而生,当互斥操作不够用而引入的。
164172
比如,线程可能需要等待某个条件为真才能继续执行,
165173
而一个忙等待循环中可能会导致所有其他线程都无法进入临界区使得条件为真时,就会发生死锁。
@@ -234,6 +242,8 @@ int main() {
234242

235243
## 7.5 原子操作与内存模型
236244

245+
*(C++11)*
246+
237247
细心的读者可能会对前一小节中生产者消费者模型的例子可能存在编译器优化导致程序出错的情况产生疑惑。
238248
例如,编译器可能对变量 `notified` 存在优化,例如将其作为一个寄存器的值,
239249
从而导致消费者线程永远无法观察到此值的变化。这是一个好问题,为了解释清楚这个问题,我们需要进一步讨论

book/zh-cn/09-others.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ order: 9
1010

1111
## 9.1 新类型
1212

13+
*(C++11)*
14+
1315
### `long long int`
1416

1517
`long long int` 并不是 C++11 最先引入的,其实早在 C99,
@@ -19,6 +21,8 @@ C++11 的工作则是正式把它纳入标准库,
1921

2022
## 9.2 noexcept 的修饰和操作
2123

24+
*(C++11)*
25+
2226
C++ 相比于 C 的一大优势就在于 C++ 本身就定义了一套完整的异常处理机制。
2327
然而在 C++11 之前,几乎没有人去使用在函数名后书写异常声明表达式,
2428
从 C++11 开始,这套机制被弃用,所以我们不去讨论也不去介绍以前这套机制是如何工作如何使用,
@@ -95,6 +99,8 @@ try {
9599

96100
## 9.3 字面量
97101

102+
*(C++11)*
103+
98104
### 原始字符串字面量
99105

100106
传统 C++ 里面要编写一个充满特殊字符的字符串其实是非常痛苦的一件事情,
@@ -147,6 +153,8 @@ int main() {
147153

148154
## 9.4 内存对齐
149155

156+
*(C++11)*
157+
150158
C++ 11 引入了两个新的关键字 `alignof``alignas` 来支持对内存对齐进行控制。
151159
`alignof` 关键字能够获得一个与平台相关的 `std::size_t` 类型的值,用于查询该平台的对齐方式。
152160
当然我们有时候并不满足于此,甚至希望自定定义结构的对齐方式,同样,C++ 11 还引入了 `alignas`
@@ -195,6 +203,8 @@ delete p;
195203

196204
## 9.5 类型双关与 `std::bit_cast`
197205

206+
*(C++20)*
207+
198208
「类型双关」(type punning) 指的是把同一段内存按另一种类型重新解读,常见于底层编程(例如读取浮点数的位模式)。许多人习惯用 `reinterpret_cast` 通过指针或引用来做这件事:
199209

200210
```cpp
@@ -221,6 +231,8 @@ float back = std::bit_cast<float>(bits);
221231

222232
## 9.6 数学特殊函数
223233

234+
*(C++17)*
235+
224236
C++17 在 `<cmath>` 中引入了一组数学特殊函数(special mathematical functions),例如 `std::riemann_zeta``std::beta``std::assoc_legendre``std::cyl_bessel_j` 等,便于科学计算与机器学习相关领域使用:
225237

226238
```cpp
@@ -234,7 +246,7 @@ double z = std::riemann_zeta(2.0); // ≈ 1.6449 (即 π²/6)
234246

235247
本节介绍的几个特性是从仍未介绍的现代 C++ 新特性里使用频次较靠前的特性了,`noexcept` 是最为重要的特性,它的一个功能在于能够阻止异常的扩散传播,有效的让编译器最大限度的优化我们的代码。
236248

237-
[返回目录](./toc.md) | [上一章](./08-filesystem.md) | [下一章 展望:C++20 简介](./10-cpp20.md)
249+
[返回目录](./toc.md) | [上一章](./08-filesystem.md) | [下一章 C++20](./10-cpp20.md)
238250

239251
## 许可
240252

0 commit comments

Comments
 (0)