jeudi 7 novembre 2019

Generic lambdas and the unary + operator

From my understanding the + operator before a lambda expression resolves it to a function pointer overload. (Post)

However I do not understand quite understand why it does not work with generic lambdas. For example:

auto foo = +[](int a) { std::cout << "foo " << a << std::endl; };  // Valid

auto bar = +[](auto a) { std::cout << "bar " << a << std::endl; }; // Fails 

// compiler error: 
// no match for ‘operator+’ (operand type is ‘main()::<lambda(auto:1)>’)

What is the intuition behind this?

Live example

Aucun commentaire:

Enregistrer un commentaire