This question already has an answer here:
There is this code:
auto fun = [](int x)->int {return x + 1; };
std::cout << typeid(fun).name() << std::endl;
The result is: Z4mainEUliE_
but c++filt doesn't seem to explain what is it. What is type of lambda expression?
The type of a lambda function is unspecified by the standard (§5.1.2):
It then goes on listing the exact properties a closure type should have.
Therefore there is no general type for a lambda function to have. The compiler will generate a new functor type with unspecified name for each lambda function
The type of a lambda expression (the so-called closure) is an unnamed class type with a function call operator automatically generated by the compiler. The internal name the compiler will give it is unspecified.
According to Paragraph 5.1.2/3 of the C++11 Standard:
Also notice, that the
name()
member function of thetype_info
class (the type returned bytypeid()
) is also implementation-dependent, and the Standard does not require it to be meaningful for a human.Per Paragraph 18.7.1:
§5.1.2/3 states:
It goes on to say more, but that's the most important bit. A lambda is basically an instance of an anonymous class.
Incidentally, the demangled form of your lambda is
main::$_0
.