C++核心准则C.170: 如果感觉需要重载lambda表达式,使用泛型lambd...
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
觉得本文有帮助?请分享给更多人。
关注【面向对象思考】轻松学习每一天!
面向对象开发,面向对象思考!
评论