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