The problem: I have a predicate bool pred(const T&) which I can feed to an algorithm like partition, but what I want is its negation (!pred). I'd prefer a solution that works regardless of what pred is exactly, but at least the solution has to work if pred is a named lambda.
I can come up with three ways of getting the negation:
1) [](const T& t){return !pred(t);} or
2) bind(logical_not<bool>(), bind(pred, _1)) or
3) not1(function<bool(const T&)>(pred))
but all of them are clumsy. I feel the lambda version (1) may be the easiest to write and read, but on the other hand I like the bind version (2) because it avoids the need to specify T's type explicitly. (3) has nothing going for it. Am I overlooking something? I thought about writing a template function function<...> neg(pred), but could not think of a way to deduce the parameter type of the callable, which would be necessary to specify a correct return type for neg, and apparently function is also less efficient than raw lambdas and function pointers.