Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext
binary_search
Prototype

template<class ForwardRange, class Value>
bool binary_search(const ForwardRange& rng, const Value& val);

template<class ForwardRange, class Value, class BinaryPredicate>
bool binary_search(const ForwardRange& rng, const Value& val, BinaryPredicate pred);

Description

binary_search returns true if and only if the value val exists in the range rng.

Definition

Defined in the header file boost/range/algorithm/binary_search.hpp

Requirements

For the non-predicate versions of binary_search:

For the predicate versions of binary_search:

Precondition:

For the non-predicate version:

rng is ordered in ascending order according to operator<.

For the predicate version:

rng is ordered in ascending order according to the function object pred.

Complexity

For non-random-access ranges, the complexity is O(N) where N is distance(rng).

For random-access ranges, the complexity is O(log N) where N is distance(rng).


PrevUpHomeNext