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_LEXICOGRAPHICAL_COMPARE_HPP_INCLUDED |
10 | #define BOOST_RANGE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_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 | |
18 | namespace boost |
19 | { |
20 | namespace range |
21 | { |
22 | |
23 | /// \brief template function lexicographic_compare |
24 | /// |
25 | /// range-based version of the lexicographic_compare std algorithm |
26 | /// |
27 | /// \pre SinglePassRange1 is a model of the SinglePassRangeConcept |
28 | /// \pre SinglePassRange2 is a model of the SinglePassRangeConcept |
29 | template<class SinglePassRange1, class SinglePassRange2> |
30 | inline bool lexicographical_compare(const SinglePassRange1& rng1, |
31 | const SinglePassRange2& rng2) |
32 | { |
33 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> )); |
34 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> )); |
35 | return std::lexicographical_compare( |
36 | boost::begin(rng1), boost::end(rng1), |
37 | boost::begin(rng2), boost::end(rng2)); |
38 | } |
39 | |
40 | /// \overload |
41 | template<class SinglePassRange1, class SinglePassRange2, |
42 | class BinaryPredicate> |
43 | inline bool lexicographical_compare(const SinglePassRange1& rng1, |
44 | const SinglePassRange2& rng2, |
45 | BinaryPredicate pred) |
46 | { |
47 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> )); |
48 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> )); |
49 | return std::lexicographical_compare( |
50 | boost::begin(rng1), boost::end(rng1), |
51 | boost::begin(rng2), boost::end(rng2), pred); |
52 | } |
53 | |
54 | } // namespace range |
55 | using range::lexicographical_compare; |
56 | } // namespace boost |
57 | |
58 | #endif // include guard |
59 | |