What is the type of lambda when deduced with “auto” in C++11?

The type of a lambda expression is unspecified.

But they are generally mere syntactic sugar for functors. A lambda is translated directly into a functor. Anything inside the [] are turned into constructor parameters and members of the functor object, and the parameters inside () are turned into parameters for the functor’s operator().

A lambda which captures no variables (nothing inside the []‘s) can be converted into a function pointer (MSVC2010 doesn’t support this, if that’s your compiler, but this conversion is part of the standard).

But the actual type of the lambda isn’t a function pointer. It’s some unspecified functor type.

Leave a Comment