The C++11 standard says (or at least, the version I have - not the final one) :
The closure type for a lambda-expression with no lambda-capture has a public non-virtual non-explicit const conversion function to pointer to function having the same parameter and return types as the closure type’s function call operator.
I understand why it is not possible to get a function pointer from a stateful lambda since a function pointer cannot hold any data by itself.
But when the captured objects are just a static members /static variable, there is no such limitation since the references to the captured objects can be hardwired in the function itself.
struct A {
static int count = 0;
void foo() {
static int bar = 0;
auto fun = [&]()->void {
count++;
bar++;
};
void(*ptrFun)();
ptrFun = fun; // forbidden by the quoted wording
}
};
Why isn't it always possible to convert a lambda to a function pointer as soon as the former is stateless ? Am I missing something or does the committee forgot this specific point ?