Horizon
lexicographical_compare.hpp
Go to the documentation of this file.
1 // 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 
26 #include <range/v3/utility/static_const.hpp>
27 
28 #include <range/v3/detail/prologue.hpp>
29 
30 namespace ranges
31 {
34  RANGES_FUNC_BEGIN(lexicographical_compare)
35 
36 
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 
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
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  }
98 } // namespace ranges
99 
100 #include <range/v3/detail/epilogue.hpp>
101 
102 #endif
template(typename Rng0, typename Rng1, typename C=less, typename P0=identity, typename P1=identity)(requires input_range< Rng0 > AND input_range< Rng1 > AND indirect_strict_weak_order< C
This is an overloaded member function, provided for convenience. It differs from the above function o...
CPP_concept sentinel_for
\concept sentinel_for
Definition: concepts.hpp:306
CPP_concept input_iterator
\concept input_iterator
Definition: concepts.hpp:362
CPP_concept indirect_strict_weak_order
\concept indirect_strict_weak_order
Definition: concepts.hpp:689
decltype(begin(declval(Rng &))) iterator_t
Definition: access.hpp:698
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition: meta.hpp:541
bool_<(T::type::value< U::type::value)> less
A Boolean integral constant wrapper around true if T::type::value is less than U::type::value; false,...
Definition: meta.hpp:255
Definition: identity.hpp:25
Definition: comparisons.hpp:50