1// Copyright Neil Groves 2009. Use, modification and
2// distribution is subject to the Boost Software License, Version
3// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5//
6//
7// For more information, see http://www.boost.org/libs/range/
8//
9#ifndef BOOST_RANGE_ALGORITHM_BINARY_SEARCH_HPP_INCLUDED
10#define BOOST_RANGE_ALGORITHM_BINARY_SEARCH_HPP_INCLUDED
11
12#include <boost/concept_check.hpp>
13#include <boost/range/begin.hpp>
14#include <boost/range/end.hpp>
15#include <boost/range/concepts.hpp>
16#include <algorithm>
17
18namespace boost
19{
20 namespace range
21 {
22
23/// \brief template function binary_search
24///
25/// range-based version of the binary_search std algorithm
26///
27/// \pre ForwardRange is a model of the ForwardRangeConcept
28/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
29template<class ForwardRange, class Value>
30inline bool binary_search(const ForwardRange& rng, const Value& val)
31{
32 BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
33 return std::binary_search(boost::begin(rng), boost::end(rng), val);
34}
35
36/// \overload
37template<class ForwardRange, class Value, class BinaryPredicate>
38inline bool binary_search(const ForwardRange& rng, const Value& val,
39 BinaryPredicate pred)
40{
41 BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
42 return std::binary_search(boost::begin(rng), boost::end(rng), val, pred);
43}
44
45 } // namespace range
46 using range::binary_search;
47} // namespace boost
48
49#endif // include guard
50

source code of boost/boost/range/algorithm/binary_search.hpp