The reference to lambda?

A simple lambda:
auto lsqr = [](const int &n) -> int { return n*n; };

int (*pointer)(const int&) = lsqr; // OK
int (&refernce)(const int&) = lsqr; // Error
//Normally, perversion
int (&perversion)(const int&) = *(int(*)(const int&)) lsqr;

Why you can make a pointer to it, but you can't make a link?
July 8th 19 at 16:04
2 answers
July 8th 19 at 16:06
Solution
For lambdas that do not capture variables in their [], defined conversion operator to pointer to function(ClosureType::operator ret(*)(params)()). This is why implicit castes in your 1 example. For reference, the compiler finds a suitable transformation.
The last example first converts a lambda to a pointer and dereference it just like a pointer.
July 8th 19 at 16:08
non-const lvalue reference to type int (const int&)

int n = 5;
const std::function& refernce = std::bind([](const int &n) {return n*n; }, n);
const int& x1 = refernce(); // out: x = 25
And the constant references to functions are generally? - florencio_Pur commented on July 8th 19 at 16:11

Find more questions by tags C++