Passing C++ Lambda Functions
There's no need to add the knee-jerk [&]
-capture. Your lambda doesn't need it:
[] (int x) -> bool { return (x == 0); }
Captureless lambdas are convertible to the corresponding function pointer, so this should work out of the box.
That said, you should probably declare the select function to accept std::function
, to which all lambdas are convertible, capturing or not:
Container<T> select(std::function<bool(const T&)> predicate) const;
You need to declare your lambda as stateless (that is, with an empty capture specification [](int x)-> bool {...}
) for it to be convertable to a function pointer.