Couldn't find_if
just be an overload of find
? That's how std::binary_search
and friends do it...
A predicate is a valid thing to find, so you could arrive at ambiguities.
Consider find_if
is renamed find
, then you have:
template <typename InputIterator, typename T>
InputIterator find(InputIterator first, InputIterator last, const T& value);
template <typename InputIterator, typename Predicate>
InputIterator find(InputIterator first, InputIterator last, Predicate pred);
What shall be done, then, with:
find(c.begin(), c.end(), x); // am I finding x, or using x to find?
Rather than try to come up with some convoluted solution to differentiate based on x
(which can't always be done*), it's easier just to separate them.
*This would be ambiguous, no matter what your scheme is or how powerful it might be†:
struct foo
{
template <typename T>
bool operator()(const T&);
};
bool operator==(const foo&, const foo&);
std::vector<foo> v = /* ... */;
foo f = /* ... */;
// f can be used both as a value and as a predicate
find(v.begin(), v.end(), f);
†Save mind reading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With