Skip to content

Commit ab01376

Browse files
committed
Update public notes
1 parent 1d6c281 commit ab01376

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

content/编程相关/编程语言/Cpp 之旅 第三版 读书笔记.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
created: 2025-10-17
3-
updated: 2025-10-20
3+
updated: 2025-10-23
44
title: C++ 之旅 第三版 读书笔记
55
---
66
也是来品读这本神作。
@@ -979,6 +979,8 @@ Arithmetic auto twice(Arithmetic auto x) { return x+x; }
979979
> - 调试,测试,然后测量它们。
980980
> - 最后,将实体类型转化为类模板参数。
981981
982+
### 可变参数模板
983+
982984
举例是 print:
983985
984986
```cpp
@@ -990,6 +992,21 @@ void print(T head, Tail... tail) {
990992
}
991993
```
992994

995+
参数声明后面的 `...` 叫作参数包。
996+
997+
还有折叠表达式
998+
999+
```cpp
1000+
template<Number T>
1001+
int sum(T... v) {
1002+
return (v + ... + 0);
1003+
}
1004+
```
1005+
1006+
这里是右折叠,从零开始,最先做运算的是最右边的元素。
1007+
1008+
左折叠的写法是 `(0+...+v)` .
9931009
1010+
折叠表达式目前仅限用于简化可变参数模板的实现。
9941011
9951012
#todo

0 commit comments

Comments
 (0)