C++核心準則C.170: 重載lambda表達式時使用泛型lambda表達式​

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(示例)

<code>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​/<code>
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


覺得本文有幫助?請分享給更多人。

面向對象開發,面向對象思考!


分享到:


相關文章: