We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1d6c281 commit ab01376Copy full SHA for ab01376
content/编程相关/编程语言/Cpp 之旅 第三版 读书笔记.md
@@ -1,6 +1,6 @@
1
---
2
created: 2025-10-17
3
-updated: 2025-10-20
+updated: 2025-10-23
4
title: C++ 之旅 第三版 读书笔记
5
6
也是来品读这本神作。
@@ -979,6 +979,8 @@ Arithmetic auto twice(Arithmetic auto x) { return x+x; }
979
> - 调试,测试,然后测量它们。
980
> - 最后,将实体类型转化为类模板参数。
981
982
+### 可变参数模板
983
+
984
举例是 print:
985
986
```cpp
@@ -990,6 +992,21 @@ void print(T head, Tail... tail) {
990
992
}
991
993
```
994
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)` .
1009
1010
+折叠表达式目前仅限用于简化可变参数模板的实现。
1011
1012
#todo
0 commit comments