It crashed into several different functions in C ++, since for reasoning it is almost impossible to say why someone did something anyway. binary_search will tell you if such an element exists. If you need to know where they are, use lower_bound and upper_bound , which will give a start and end iterator, respectively. There is also equal_range , which gives you both a start and an end right away.
Since others seem to think that it is obvious why it was created this way, I will argue about why it is difficult / impossible to answer if you are not Alexander Stepanov or someone who worked with him.
Unfortunately, the SGI STL FAQ does not mention binary_search at all. This explains that list<>::size is linear time or pop returning void . It seems like they thought binary_search was special enough to document it.
Take a look at a possible performance improvement mentioned in @ user2899162:
You can find the original implementation of the SGI STL binary_search here . Looking at this, you can greatly simplify it (we all know how terrible the internal names in the standard library are):
template <class ForwardIter, class V> bool binary_search(ForwardIter first, ForwardIter last, const V& value) { ForwardIter it = lower_bound(first, last, value); return it != last && !(value < *it); }
As you can see, it was implemented in terms of lower_bound and got the exact same performance. If they really wanted him to take advantage of possible performance improvements, they would not have implemented it in terms of a slower one, so it does not seem like they did it that way.
Now let's look at it just as a convenient function
This just a convenient feature seems more likely, but looking through the STL, you will find many other algorithms where this could be possible. Looking at the above implementation, you will see that it is just trivially more than std::find(begin, end, value) != end; but we have to write all the time and we donβt have a convenience function that returns a bool . Why is it here and not all other algorithms too? This is not very obvious and cannot be simply explained.
In conclusion, I find this far from obvious and I do not know if I can confidently and honestly answer it.