Skip to content

Commit 811c5ef

Browse files
committed
book: refine initializer_list in variadic template
see changkun#65
1 parent 86d84d2 commit 811c5ef

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

book/zh-cn/02-usability.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,6 @@ void printf2(T0 t0, T... t) {
722722
723723
**3. 初始化列表展开**
724724
725-
> 这个方法需要之后介绍的知识,读者可以简单阅读一下,将这个代码段保存,在后面的内容了解过了之后再回过头来阅读此处方法会大有收获。
726-
727725
递归模板函数是一种标准的做法,但缺点显而易见的在于必须定义一个终止递归的函数。
728726
729727
这里介绍一种使用初始化列表展开的黑魔法:
@@ -738,7 +736,7 @@ auto printf3(T value, Ts... args) {
738736
}
739737
```
740738

741-
在这个代码中,额外使用了 C++11 中提供的初始化列表以及 Lambda 表达式的特性(下一节中将提到),而 std::initializer_list 也是 C++11 新引入的容器(以后会介绍到)
739+
在这个代码中,额外使用了 C++11 中提供的初始化列表以及 Lambda 表达式的特性(下一节中将提到)。
742740

743741
通过初始化列表,`(lambda 表达式, value)...` 将会被展开。由于逗号表达式的出现,首先会执行前面的 lambda 表达式,完成参数的输出。
744742
为了避免编译器警告,我们可以将 `std::initializer_list` 显式的转为 `void`

0 commit comments

Comments
 (0)