Horizon
Loading...
Searching...
No Matches
ends_with.hpp
Go to the documentation of this file.
1
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
21#include <range/v3/detail/config.hpp>
28
29#include <range/v3/detail/prologue.hpp>
30
31namespace 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)(
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
The forward_iterator concept.
The forward_range concept.
The indirectly_comparable concept.
The input_iterator concept.
The input_range concept.
The sentinel_for concept.
The sized_range concept.
The sized_sentinel_for concept.
decltype(begin(declval(Rng &))) iterator_t
Definition access.hpp:698
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