Skip to content

Commit 2e9eed9

Browse files
committed
book: reword generic lambda
Fixes changkun#242
1 parent e50e3c6 commit 2e9eed9

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

book/en-us/03-runtime.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,9 @@ initialize it in the expression.
126126

127127
In the previous section, we mentioned that the `auto` keyword cannot be used
128128
in the parameter list because it would conflict with the functionality of the template.
129-
But Lambda expressions are not ordinary functions, so Lambda expressions are not templated.
130-
This has caused us some trouble: the parameter table cannot be generalized,
131-
and the parameter table type must be clarified.
132-
133-
Fortunately, this trouble only exists in C++11, starting with C++14.
134-
The formal parameters of the Lambda function can use the `auto` keyword
135-
to generate generic meanings:
129+
But lambda expressions are not regular functions, without further specification on the typed parameter list, lambda expressions cannot utilize templates. Fortunately, this trouble
130+
only exists in C++11, starting with C++14. The formal parameters of the lambda function
131+
can use the `auto` keyword to utilize template generics:
136132

137133
```cpp
138134
void lambda_generic() {
@@ -221,7 +217,7 @@ int foo(int a, int b, int c) {
221217
;
222218
}
223219
int main() {
224-
// bind parameter 1, 2 on function foo,
220+
// bind parameter 1, 2 on function foo,
225221
// and use std::placeholders::_1 as placeholder for the first parameter.
226222
auto bindFoo = std::bind(foo, std::placeholders::_1, 1,2);
227223
// when call bindFoo, we only need one param left
@@ -483,8 +479,8 @@ int main() {
483479
// "str: Hello world."
484480
std::cout << "str: " << str << std::endl;
485481

486-
// use push_back(const T&&),
487-
// no copy the string will be moved to vector,
482+
// use push_back(const T&&),
483+
// no copy the string will be moved to vector,
488484
// and therefore std::move can reduce copy cost
489485
v.push_back(std::move(str));
490486
// str is empty now

book/zh-cn/03-runtime.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,9 @@ void lambda_expression_capture() {
107107
### 泛型 Lambda
108108

109109
上一节中我们提到了 `auto` 关键字不能够用在参数表里,这是因为这样的写法会与模板的功能产生冲突。
110-
但是 Lambda 表达式并不是普通函数,所以 Lambda 表达式并不能够模板化。
111-
这就为我们造成了一定程度上的麻烦:参数表不能够泛化,必须明确参数表类型。
112-
113-
幸运的是,这种麻烦只存在于 C++11 中,从 C++14 开始,
114-
Lambda 函数的形式参数可以使用 `auto` 关键字来产生意义上的泛型:
110+
但是 Lambda 表达式并不是普通函数,所以在没有明确指明参数表类型的情况下,Lambda 表达式并不能够模板化。
111+
幸运的是,这种麻烦只存在于 C++11 中,从 C++14 开始,Lambda 函数的形式参数可以使用 `auto`
112+
关键字来产生意义上的泛型:
115113

116114
```cpp
117115
auto add = [](auto x, auto y) {

0 commit comments

Comments
 (0)