In the C ++ 11 standard (or at least I have a version, not the latest):
The closure type for a lambda expression with no lambda capture has a public non-virtual implicit function of converting const to a pointer to work with the same parameters and return types as closing a type of a function call statement.
I understand why it is not possible to get a function pointer from lambda with state, since a function pointer cannot store any data by itself.
But when captured objects are only static members / static variable, there is no such restriction, since references to captured objects can be rigidly attached to the function itself.
struct A { static int count = 0; void foo() { static int bar = 0; auto fun = [&]()->void { count++; bar++; }; void(*ptrFun)(); ptrFun = fun;
Why is it not always possible to convert a lambda to a function pointer once the first is stateless? Am I missing something or did the committee forget this particular point?
source share