C++核心準(zhǔn)則C.170: 如果感覺(jué)需要重載lambda表達(dá)式,使用泛型lambd...

C.170: If you feel like overloading a lambda, use a generic lambda
C.170: 如果需要重載lambda表達(dá)式,使用泛型lambda表達(dá)式
Reason(原因)
You cannot overload by defining two different lambdas with the same name.
你無(wú)法以為兩個(gè)不同的lambda表達(dá)式取相同名字的方式來(lái)實(shí)現(xiàn)重載。
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) { /* ... */ }; // OKEnforcement(實(shí)施建議)
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
覺(jué)得本文有幫助?請(qǐng)分享給更多人。
關(guān)注【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!
面向?qū)ο箝_(kāi)發(fā),面向?qū)ο笏伎迹?/span>
評(píng)論
圖片
表情
