The following code fails to compile (both GCC and clang say the lambda isn't a proper function?)
#include <iostream>
using namespace std;
void apply(void f(int)) {
f(10);
f(20);
f(30);
}
int main()
{
int col = 42;
apply([col](int data) -> void {
cout << data << ' ' << col << endl;
});
}
clang++ says:
fails.cc:5:6: note: candidate function not viable: no known conversion from '(lambda at
fails.cc:15:8)' to 'void (*)(int)' for 1st argument
void apply(void f(int)) {
^
1 error generated.
If you get rid of the col
capture and it's use, it compiles and works fine. Rummaging in cppreference just tells me everything is OK...
What would be the point of lambdas if captures aren't allowed?