| 1 |
/// \file |
| 2 |
// Range v3 library |
| 3 |
// |
| 4 |
// Copyright Eric Niebler 2013-present |
| 5 |
// |
| 6 |
// Use, modification and distribution is subject to the |
| 7 |
// Boost Software License, Version 1.0. (See accompanying |
| 8 |
// file LICENSE_1_0.txt or copy at |
| 9 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 10 |
// |
| 11 |
// Project home: https://github.com/ericniebler/range-v3 |
| 12 |
// |
| 13 |
#ifndef RANGES_V3_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP |
| 14 |
#define RANGES_V3_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP |
| 15 |
|
| 16 |
#include <range/v3/range_fwd.hpp> |
| 17 |
|
| 18 |
#include <range/v3/functional/comparisons.hpp> |
| 19 |
#include <range/v3/functional/identity.hpp> |
| 20 |
#include <range/v3/functional/invoke.hpp> |
| 21 |
#include <range/v3/iterator/concepts.hpp> |
| 22 |
#include <range/v3/iterator/traits.hpp> |
| 23 |
#include <range/v3/range/access.hpp> |
| 24 |
#include <range/v3/range/concepts.hpp> |
| 25 |
#include <range/v3/range/traits.hpp> |
| 26 |
#include <range/v3/utility/static_const.hpp> |
| 27 |
|
| 28 |
#include <range/v3/detail/prologue.hpp> |
| 29 |
|
| 30 |
namespace ranges |
| 31 |
{ |
| 32 |
/// \addtogroup group-algorithms |
| 33 |
/// @{ |
| 34 |
RANGES_FUNC_BEGIN(lexicographical_compare) |
| 35 |
|
| 36 |
/// \brief function template \c lexicographical_compare |
| 37 |
template(typename I0, |
| 38 |
typename S0, |
| 39 |
typename I1, |
| 40 |
typename S1, |
| 41 |
typename C = less, |
| 42 |
typename P0 = identity, |
| 43 |
typename P1 = identity)( |
| 44 |
requires input_iterator<I0> AND sentinel_for<S0, I0> AND |
| 45 |
input_iterator<I1> AND sentinel_for<S1, I1> AND |
| 46 |
indirect_strict_weak_order<C, projected<I0, P0>, projected<I1, P1>>) |
| 47 |
constexpr bool RANGES_FUNC(lexicographical_compare)(I0 begin0, |
| 48 |
S0 end0, |
| 49 |
I1 begin1, |
| 50 |
S1 end1, |
| 51 |
C pred = C{}, |
| 52 |
P0 proj0 = P0{}, |
| 53 |
P1 proj1 = P1{}) |
| 54 |
{ |
| 55 |
for(; begin1 != end1; ++begin0, ++begin1) |
| 56 |
{ |
| 57 |
if(begin0 == end0 || |
| 58 |
invoke(pred, invoke(proj0, *begin0), invoke(proj1, *begin1))) |
| 59 |
return true; |
| 60 |
if(invoke(pred, invoke(proj1, *begin1), invoke(proj0, *begin0))) |
| 61 |
return false; |
| 62 |
} |
| 63 |
return false; |
| 64 |
} |
| 65 |
|
| 66 |
/// \overload |
| 67 |
template(typename Rng0, |
| 68 |
typename Rng1, |
| 69 |
typename C = less, |
| 70 |
typename P0 = identity, |
| 71 |
typename P1 = identity)( |
| 72 |
requires input_range<Rng0> AND input_range<Rng1> AND |
| 73 |
indirect_strict_weak_order<C, |
| 74 |
projected<iterator_t<Rng0>, P0>, |
| 75 |
projected<iterator_t<Rng1>, P1>>) |
| 76 |
constexpr bool RANGES_FUNC(lexicographical_compare)(Rng0 && rng0, |
| 77 |
Rng1 && rng1, |
| 78 |
C pred = C{}, |
| 79 |
P0 proj0 = P0{}, |
| 80 |
P1 proj1 = P1{}) // |
| 81 |
{ |
| 82 |
return (*this)(begin(rng0), |
| 83 |
end(rng0), |
| 84 |
begin(rng1), |
| 85 |
end(rng1), |
| 86 |
std::move(pred), |
| 87 |
std::move(proj0), |
| 88 |
std::move(proj1)); |
| 89 |
} |
| 90 |
|
| 91 |
RANGES_FUNC_END(lexicographical_compare) |
| 92 |
|
| 93 |
namespace cpp20 |
| 94 |
{ |
| 95 |
using ranges::lexicographical_compare; |
| 96 |
} |
| 97 |
/// @} |
| 98 |
} // namespace ranges |
| 99 |
|
| 100 |
#include <range/v3/detail/epilogue.hpp> |
| 101 |
|
| 102 |
#endif |