C++核心准则C.170: 如果感觉需要重载lambda表达式,使用泛型lambda表达式

C.170: If you feel like overloading a lambda, use a generic lambda

C.170: 如果需要重载lambda表达式,使用泛型lambda表达式

 

Reason(原因)

You cannot overload by defining two different lambdas with the same name.

你无法以为两个不同的lambda表达式取相同名字的方式来实现重载。

 

Example(示例)

void f(int);
void f(double);
auto f = [](char);   // error: cannot overload variable and function

auto g = [](int) { /* ... */ };
auto g = [](double) { /* ... */ };   // error: cannot overload variables

auto h = [](auto) { /* ... */ };   // OK

 

Enforcement(实施建议)

The compiler catches the attempt to overload a lambda.

 

原文链接:

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c170-if-you-feel-like-overloading-a-lambda-use-a-generic-lambda

 


 

觉得本文有帮助?欢迎点赞并分享给更多的人。

阅读更多更新文章,请关注微信公众号【面向对象思考】

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章