How to perfectly forward `auto&&` in a generic lambda?
问题 C++14 supports generic lambdas. However, the following code is rejected by clang 3.4. #include <utility> void f(int); void f(int&); int main() { [](auto&& v) { f(std::forward<auto>(v)); }(8); // error } How to perfectly forward auto&& in a generic lambda? 回答1: auto is not a type so I’m not surprised this doesn’t work. But can’t you use decltype ? [](auto&& v) { f(std::forward<decltype(v)>(v)); }(8); Scott Meyers has more details. 来源: https://stackoverflow.com/questions/24535430/how-to