Debian Codegraph @

3rd_party/range-v3/range/v3/algorithm/ends_with.hpp

raw
1 /// \file
2 // 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
20 #include <range/v3/algorithm/equal.hpp>
21 #include <range/v3/detail/config.hpp>
22 #include <range/v3/functional/comparisons.hpp>
23 #include <range/v3/functional/identity.hpp>
24 #include <range/v3/iterator/concepts.hpp>
25 #include <range/v3/iterator/operations.hpp>
26 #include <range/v3/range/access.hpp>
27 #include <range/v3/range/concepts.hpp>
28
29 #include <range/v3/detail/prologue.hpp>
30
31 namespace ranges
32 {
33 /// \addtogroup group-algorithms
34 /// @{
35 RANGES_FUNC_BEGIN(ends_with)
36
37 /// \brief function template \c ends_with
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
70 /// \overload
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)
95 /// @}
96 } // namespace ranges
97
98 #include <range/v3/detail/epilogue.hpp>
99
100 #endif