C++ 为什么一些STL算法提供额外的'_如果';函数而不是重载?

C++ 为什么一些STL算法提供额外的'_如果';函数而不是重载?,c++,c++11,stl,stl-algorithm,C++,C++11,Stl,Stl Algorithm,为什么一些STL算法提供了一个额外的“if'函数而不是重载它? // example: find(beg, end, val); find_if(beg, end, pred); 如果函数,它们就不能重载这些算法而不是生成额外的\u吗?这些算法提供了一个命名版本而不是重载版本,因为两个版本的算法使用相同数量的参数。因此,可能会导致歧义过载 为了避免任何可能的歧义,该库为这些算法提供了单独的命名版本,find\u(如果是其中之一)。目前尚不清楚重载解析一般如何工作。如果容器包含谓词呢 struc

为什么一些STL算法提供了一个额外的
“if'
函数而不是重载它?

// example:
find(beg, end, val);
find_if(beg, end, pred);

如果函数,它们就不能重载这些算法而不是生成额外的
\u吗?

这些算法提供了一个命名版本而不是重载版本,因为两个版本的算法使用相同数量的参数。因此,可能会导致歧义过载


为了避免任何可能的歧义,该库为这些算法提供了单独的命名版本,
find\u(如果
是其中之一)。

目前尚不清楚重载解析一般如何工作。如果容器包含谓词呢

struct pred
{
  bool operator()(const pred&) const;
  friend bool operator==(const pred&,const pred&);
};

std::vector<pred> v;
pred p;
std::find(v.begin(), v.end(), p); // what should happen here?
“稀有”?如果没有一些SFINAE技巧,它们将始终无法通过过载分辨率进行区分。
struct foo {};

struct pred
{
  bool operator()(const foo&) const;
};

bool operator==(const foo&, const pred&);

int main()
{
  std::vector<foo> v;
  pred p;
  std::find(v.begin(), v.end(), p);    // What should this do?
  std::find_if(v.begin(), v.end(), p); // Here, it is clear.
}