2 Copyright 2010 Neil Groves
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 [section:binary_search binary_search]
11 template<class ForwardRange, class Value>
12 bool binary_search(const ForwardRange& rng, const Value& val);
14 template<class ForwardRange, class Value, class BinaryPredicate>
15 bool binary_search(const ForwardRange& rng, const Value& val, BinaryPredicate pred);
20 `binary_search` returns `true` if and only if the value `val` exists in the range `rng`.
24 Defined in the header file `boost/range/algorithm/binary_search.hpp`
26 [heading Requirements]
28 [*For the non-predicate versions of binary_search:]
30 * `ForwardRange` is a model of the __forward_range__ Concept.
31 * `Value` is a model of the `LessThanComparableConcept`.
32 * The ordering of objects of type `Value` is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements.
33 * `ForwardRange`'s value type is the same type as `Value`.
35 [*For the predicate versions of binary_search:]
37 * `ForwardRange` is a model of the __forward_range__ Concept.
38 * `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`.
39 * `ForwardRange`'s value type is the same type as `Value`.
40 * `ForwardRange`'s value type is convertible to `BinaryPredicate`'s argument type.
42 [heading Precondition:]
44 [*For the non-predicate version:]
46 `rng` is ordered in ascending order according to `operator<`.
48 [*For the predicate version:]
50 `rng` is ordered in ascending order according to the function object `pred`.
54 For non-random-access ranges, the complexity is `O(N)` where `N` is `distance(rng)`.
56 For random-access ranges, the complexity is `O(log N)` where `N` is `distance(rng)`.