Update item34.md

This commit is contained in:
猫耳堀川雷鼓 2021-03-15 20:55:52 +08:00 committed by GitHub
parent 0460131518
commit b92311739d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -192,7 +192,7 @@ auto betweenB =
std::bind(std::less_equal<int>(), _1, highVal));
```
当然在C++11中*lambda*也不能采用`auto`参,因此它也必须指定一个类型:
当然在C++11中*lambda*也不能采用`auto`参,因此它也必须指定一个类型:
```c++
auto betweenL = //C++11版本
@ -247,7 +247,7 @@ compressRateB(CompLevel::High); //实参如何传递?
与*lambda*相比,使用`std::bind`进行编码的代码可读性较低,表达能力较低,并且效率可能较低。 在C++14中没有`std::bind`的合理用例。 但是在C++11中可以在两个受约束的情况下证明使用`std::bind`是合理的:
+ **移动捕获**。C++11的*lambda*不提供移动捕获,但是可以通过结合*lambda*和`std::bind`来模拟。 有关详细信息,请参阅[Item32](https://github.com/kelthuzadx/EffectiveModernCppChinese/blob/master/6.LambdaExpressions/item32.md)该条款还解释了在C++14中*lambda*对初始化捕获的支持消除了这个模拟的需求。
+ **多态函数对象**。因为bind对象上的函数调用运算符使用完美转发所以它可以接受任何类型的参(以[Item30](https://github.com/kelthuzadx/EffectiveModernCppChinese/blob/master/5.RRefMovSemPerfForw/item30.md)中描述的完美转发的限制为界限)。当你要绑定带有模板化函数调用运算符的对象时,此功能很有用。 例如这个类,
+ **多态函数对象**。因为bind对象上的函数调用运算符使用完美转发所以它可以接受任何类型的参(以[Item30](https://github.com/kelthuzadx/EffectiveModernCppChinese/blob/master/5.RRefMovSemPerfForw/item30.md)中描述的完美转发的限制为界限)。当你要绑定带有模板化函数调用运算符的对象时,此功能很有用。 例如这个类,
```c++
class PolyWidget {
@ -273,7 +273,7 @@ boundPW(nullptr); //传nullptr给PolyWidget::operator()
boundPW("Rosebud"); //传字面值给PolyWidget::operator()
```
这一点无法使用C++11的*lambda*做到。 但是在C++14中可以通过带有`auto`参的*lambda*轻松实现:
这一点无法使用C++11的*lambda*做到。 但是在C++14中可以通过带有`auto`参的*lambda*轻松实现:
```c++
auto boundPW = [pw](const auto& param) //C++14