cpp/algorithm/binary search

Checks if an element equivalent to appears within the range.

For to succeed, the range  must be at least partially ordered with respect to, i.e. it must satisfy all of the following requirements:
 * partitioned with respect to or  (that is, all elements for which the expression is  precede all elements for which the expression is )
 * partitioned with respect to or
 * for all elements, if or  is  then  or  is also

A fully-sorted range meets these criteria.

The first version uses to compare the elements, the second version uses the given comparison function.

Return value
if an element equal to is found,  otherwise.

Complexity
The number of comparisons performed is logarithmic in the distance between and  (at most $log 2(last - first) + O(1)$ comparisons). However, for non-s, number of iterator increments is linear.

Possible implementation
See also the implementations in libstdc++ and libc++.