Couldn\'t find_if
just be an overload of find
? That\'s how std::binary_search
and friends do it...
It can't have the same name because there would be an ambiguity. Suppose that we had a find
overload instead of find_if
. Then suppose:
// Pseudo-code
struct finder
{
bool operator()(const T&) const { ... }
bool operator==(const finder& right) const { ... }
}
std::vector finders;
finder my_finder;
std::find(finders.begin(), finders.end(), my_finder);
The find
would have no way to resolve the inconsistency: Should it attempt to find the finder
in the container, or use the finder
to do the find operation? To solve this problem they created two function names.