I read somewhere that a lambda function should decay to function pointer if the capture list is empty. The only reference I can find now is n3052. With g++ (4.5 & 4.6) it works as expected, unless the lambda is declared within template code.
For example the following code compiles:
void foo() {
void (*f)(void) = []{};
}
But it doesn't compile anymore when templated (if foo
is actually called elsewhere):
template<class T>
void foo() {
void (*f)(void) = []{};
}
In the reference above, I don't see an explanation of this behaviour. Is this a temporary limitation of g++, and if not, is there a (technical) reason not to allow this?