The textbook functional programming introduction example "return a function with a curried parameter" in C++ does not compile for me:
// return a function x(v) parameterized with b, which tells if v > b
bool (*greater(int))(int b)
{
return [b](int v) { return v > b; };
}
It says that identifier b
in the capture [b]
is undefined. I know that I'm being naive here, but where is my error?
EDIT: as @some-programmer-dude pointed out correctly, the function signature is wrong.
greater
is a function accepting an int b
returning ( a pointer *
to a function accepting an (int)
returning a bool
).
// return a function x(v) parameterized with b, which tells if v > b
bool (*greater(int b))(int)
{
return [b](int v) { return v > b; };
}
This of course does not remove the original question which all three replies answered correctly.