Horizon
ends_with.hpp
Go to the documentation of this file.
1 // Range v3 library
3 //
4 // Copyright Johel Guerrero 2019
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_ENDS_WITH_HPP
14 #define RANGES_V3_ALGORITHM_ENDS_WITH_HPP
15 
16 #include <utility>
17 
18 #include <concepts/concepts.hpp>
19 
21 #include <range/v3/detail/config.hpp>
28 
29 #include <range/v3/detail/prologue.hpp>
30 
31 namespace ranges
32 {
35  RANGES_FUNC_BEGIN(ends_with)
36 
37 
38  template(typename I0,
39  typename S0,
40  typename I1,
41  typename S1,
42  typename C = equal_to,
43  typename P0 = identity,
44  typename P1 = identity)(
45  requires ((forward_iterator<I0> && sentinel_for<S0, I0>) ||
46  (input_iterator<I0> && sized_sentinel_for<S0, I0>)) AND
47  ((forward_iterator<I1> && sentinel_for<S1, I1>) ||
48  (input_iterator<I1> && sized_sentinel_for<S1, I1>)) AND
49  indirectly_comparable<I0, I1, C, P0, P1>)
50  constexpr bool RANGES_FUNC(ends_with)(I0 begin0,
51  S0 end0,
52  I1 begin1,
53  S1 end1,
54  C pred = C{},
55  P0 proj0 = P0{},
56  P1 proj1 = P1{}) //
57  {
58  const auto drop = distance(begin0, end0) - distance(begin1, end1);
59  if(drop < 0)
60  return false;
61  return equal(next(std::move(begin0), drop),
62  std::move(end0),
63  std::move(begin1),
64  std::move(end1),
65  std::move(pred),
66  std::move(proj0),
67  std::move(proj1));
68  }
69 
71  template(typename Rng0,
72  typename Rng1,
73  typename C = equal_to,
74  typename P0 = identity,
75  typename P1 = identity)(
76  requires (forward_range<Rng0> || (input_range<Rng0> && sized_range<Rng0>)) AND
77  (forward_range<Rng1> || (input_range<Rng1> && sized_range<Rng1>)) AND
78  indirectly_comparable<iterator_t<Rng0>, iterator_t<Rng1>, C, P0, P1>)
79  constexpr bool RANGES_FUNC(ends_with)(
80  Rng0 && rng0, Rng1 && rng1, C pred = C{}, P0 proj0 = P0{}, P1 proj1 = P1{}) //
81  {
82  const auto drop = distance(rng0) - distance(rng1);
83  if(drop < 0)
84  return false;
85  return equal(next(begin(rng0), drop),
86  end(rng0),
87  begin(rng1),
88  end(rng1),
89  std::move(pred),
90  std::move(proj0),
91  std::move(proj1));
92  }
93 
94  RANGES_FUNC_END(ends_with)
96 } // namespace ranges
97 
98 #include <range/v3/detail/epilogue.hpp>
99 
100 #endif
template(typename Rng0, typename Rng1, typename C=equal_to, typename P0=identity, typename P1=identity)(requires(forward_range< Rng0 >||(input_range< Rng0 > &&sized_range< Rng0 >)) AND(forward_range< Rng1 >||(input_range< Rng1 > &&sized_range< Rng1 >)) AND indirectly_comparable< iterator_t< Rng0 >
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 indirectly_comparable
\concept indirectly_comparable
Definition: concepts.hpp:832
CPP_concept input_iterator
\concept input_iterator
Definition: concepts.hpp:362
CPP_concept sized_sentinel_for
\concept sized_sentinel_for
Definition: concepts.hpp:332
CPP_concept forward_iterator
\concept forward_iterator
Definition: concepts.hpp:370
decltype(begin(declval(Rng &))) iterator_t
Definition: access.hpp:698
bool_< T::type::value==U::type::value > equal_to
A Boolean integral constant wrapper around the result of comparing T::type::value and U::type::value ...
Definition: meta.hpp:237
drop_c< L, N::type::value > drop
Return a new meta::list by removing the first N elements from L.
Definition: meta.hpp:2037
Definition: comparisons.hpp:28
Definition: identity.hpp:25