Why does the standard library have find and find_if?

前端 未结 4 936
挽巷
挽巷 2021-01-11 16:06

Couldn\'t find_if just be an overload of find? That\'s how std::binary_search and friends do it...

4条回答
  •  别那么骄傲
    2021-01-11 16:42

    Here's what Stroustrup said (The C++ Programming Language, 18.5.2):

    If find() and find_if() had the same name, surprising abmiguities would have resulted. In general, the _if suffix is used to indicate that an algrithm takes a predicate.

    As to what exactly that "ambiguity" is, Steve Jessop answered that in his (top rated) answer to this SO question.

    (note: that question may actually qualify as the same question as this one. I'm not quite smart enough in C++ arcania to decide).

提交回复
热议问题