xref: /llvm-project/libcxx/include/__algorithm/ranges_find_end.h (revision d10dc5a06fac4dcabf2264c64c8672c6f6ae36fb)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef _LIBCPP___ALGORITHM_RANGES_FIND_END_H
10 #define _LIBCPP___ALGORITHM_RANGES_FIND_END_H
11 
12 #include <__algorithm/find_end.h>
13 #include <__algorithm/iterator_operations.h>
14 #include <__algorithm/ranges_iterator_concept.h>
15 #include <__config>
16 #include <__functional/identity.h>
17 #include <__functional/ranges_operations.h>
18 #include <__iterator/concepts.h>
19 #include <__iterator/indirectly_comparable.h>
20 #include <__iterator/iterator_traits.h>
21 #include <__ranges/access.h>
22 #include <__ranges/concepts.h>
23 #include <__ranges/subrange.h>
24 #include <__utility/pair.h>
25 
26 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27 #  pragma GCC system_header
28 #endif
29 
30 _LIBCPP_PUSH_MACROS
31 #include <__undef_macros>
32 
33 #if _LIBCPP_STD_VER >= 20
34 
35 _LIBCPP_BEGIN_NAMESPACE_STD
36 
37 namespace ranges {
38 struct __find_end {
39   template <forward_iterator _Iter1,
40             sentinel_for<_Iter1> _Sent1,
41             forward_iterator _Iter2,
42             sentinel_for<_Iter2> _Sent2,
43             class _Pred  = ranges::equal_to,
44             class _Proj1 = identity,
45             class _Proj2 = identity>
46     requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
47   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter1> operator()(
48       _Iter1 __first1,
49       _Sent1 __last1,
50       _Iter2 __first2,
51       _Sent2 __last2,
52       _Pred __pred   = {},
53       _Proj1 __proj1 = {},
54       _Proj2 __proj2 = {}) const {
55     auto __ret = std::__find_end_impl<_RangeAlgPolicy>(
56         __first1,
57         __last1,
58         __first2,
59         __last2,
60         __pred,
61         __proj1,
62         __proj2,
63         __iterator_concept<_Iter1>(),
64         __iterator_concept<_Iter2>());
65     return {__ret.first, __ret.second};
66   }
67 
68   template <forward_range _Range1,
69             forward_range _Range2,
70             class _Pred  = ranges::equal_to,
71             class _Proj1 = identity,
72             class _Proj2 = identity>
73     requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
74   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range1> operator()(
75       _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
76     auto __ret = std::__find_end_impl<_RangeAlgPolicy>(
77         ranges::begin(__range1),
78         ranges::end(__range1),
79         ranges::begin(__range2),
80         ranges::end(__range2),
81         __pred,
82         __proj1,
83         __proj2,
84         __iterator_concept<iterator_t<_Range1>>(),
85         __iterator_concept<iterator_t<_Range2>>());
86     return {__ret.first, __ret.second};
87   }
88 };
89 
90 inline namespace __cpo {
91 inline constexpr auto find_end = __find_end{};
92 } // namespace __cpo
93 } // namespace ranges
94 
95 _LIBCPP_END_NAMESPACE_STD
96 
97 #endif // _LIBCPP_STD_VER >= 20
98 
99 _LIBCPP_POP_MACROS
100 
101 #endif // _LIBCPP___ALGORITHM_RANGES_FIND_END_H
102