You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: book/en-us/06-regex.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,8 @@ With these two tables, we can usually read almost all regular expressions.
65
65
66
66
## 6.2 `std::regex` and Its Related
67
67
68
+
*(since C++11)*
69
+
68
70
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.
69
71
70
72
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.
Copy file name to clipboardExpand all lines: book/en-us/07-thread.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ order: 7
10
10
11
11
## 7.1 Basic of Parallelism
12
12
13
+
*(since C++11)*
14
+
13
15
`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.
14
16
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:
15
17
@@ -28,6 +30,8 @@ int main() {
28
30
29
31
## 7.2 Mutex and Critical Section
30
32
33
+
*(since C++11)*
34
+
31
35
We have already learned the basics of concurrency technology in the operating system, or the database, and `mutex` is one of the cores.
32
36
C++11 introduces a class related to `mutex`, with all related functions in the `<mutex>` header file.
33
37
@@ -117,6 +121,8 @@ int main() {
117
121
118
122
## 7.3 Future
119
123
124
+
*(since C++11)*
125
+
120
126
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.
121
127
To understand this feature, we need to understand the multi-threaded behavior before C++11.
122
128
@@ -157,6 +163,8 @@ After encapsulating the target to be called, you can use `get_future()` to get a
157
163
158
164
## 7.4 Condition Variable
159
165
166
+
*(since C++11)*
167
+
160
168
The condition variable `std::condition_variable` was born to solve the deadlock and was introduced when the mutex operation was not enough.
161
169
For example, a thread may need to wait for a condition to be true to continue execution.
162
170
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
229
237
230
238
## 7.5 Atomic Operation and Memory Model
231
239
240
+
*(since C++11)*
241
+
232
242
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.
233
243
For example, the compiler may have optimizations for the variable `notified`, such as the value of a register.
234
244
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?
Copy file name to clipboardExpand all lines: book/en-us/09-others.md
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ order: 9
10
10
11
11
## 9.1 New Type
12
12
13
+
*(since C++11)*
14
+
13
15
### `long long int`
14
16
15
17
`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.
20
22
21
23
## 9.2 `noexcept` and Its Operations
22
24
25
+
*(since C++11)*
26
+
23
27
One of the big advantages of C++ over C is that
24
28
C++ itself defines a complete set of exception handling mechanisms.
25
29
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()
104
108
105
109
## 9.3 Literal
106
110
111
+
*(since C++11)*
112
+
107
113
### Raw String Literal
108
114
109
115
In traditional C++, it is very painful to write a string full of
@@ -159,6 +165,8 @@ Custom literals support four literals:
159
165
160
166
## 9.4 Memory Alignment
161
167
168
+
*(since C++11)*
169
+
162
170
C++ 11 introduces two new keywords, `alignof` and `alignas`, to support control of memory alignment.
163
171
The `alignof` keyword can get a platform-dependent value of type `std::size_t` to query the alignment of the platform.
164
172
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;
207
215
208
216
## 9.5 Type punning and `std::bit_cast`
209
217
218
+
*(since C++20)*
219
+
210
220
"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:
211
221
212
222
```cpp
@@ -233,6 +243,8 @@ float back = std::bit_cast<float>(bits);
233
243
234
244
## 9.6 Mathematical special functions
235
245
246
+
*(since C++17)*
247
+
236
248
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:
237
249
238
250
```cpp
@@ -250,7 +262,7 @@ have not yet been introduced. `noexcept` is the most important feature.
250
262
One of its features is to prevent the spread of anomalies,
251
263
effective Let the compiler optimize our code to the maximum extent possible.
252
264
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)
0 commit comments