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 <__config> 15 #include <__functional/identity.h> 16 #include <__functional/ranges_operations.h> 17 #include <__iterator/concepts.h> 18 #include <__iterator/indirectly_comparable.h> 19 #include <__iterator/iterator_traits.h> 20 #include <__ranges/access.h> 21 #include <__ranges/concepts.h> 22 #include <__ranges/subrange.h> 23 24 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 25 # pragma GCC system_header 26 #endif 27 28 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 29 30 _LIBCPP_BEGIN_NAMESPACE_STD 31 32 template <class _Iter> 33 consteval auto __get_iterator_concept() { 34 if constexpr (contiguous_iterator<_Iter>) 35 return contiguous_iterator_tag(); 36 else if constexpr (random_access_iterator<_Iter>) 37 return random_access_iterator_tag(); 38 else if constexpr (bidirectional_iterator<_Iter>) 39 return bidirectional_iterator_tag(); 40 else if constexpr (forward_iterator<_Iter>) 41 return forward_iterator_tag(); 42 else if constexpr (input_iterator<_Iter>) 43 return input_iterator_tag(); 44 } 45 46 template <class _Iter> 47 using __iterator_concept = decltype(__get_iterator_concept<_Iter>()); 48 49 namespace ranges { 50 namespace __find_end { 51 struct __fn { 52 template <forward_iterator _Iter1, sentinel_for<_Iter1> _Sent1, 53 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2, 54 class _Pred = ranges::equal_to, 55 class _Proj1 = identity, 56 class _Proj2 = identity> 57 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> 58 _LIBCPP_HIDE_FROM_ABI constexpr 59 subrange<_Iter1> operator()(_Iter1 __first1, _Sent1 __last1, 60 _Iter2 __first2, _Sent2 __last2, 61 _Pred __pred = {}, 62 _Proj1 __proj1 = {}, 63 _Proj2 __proj2 = {}) const { 64 auto __ret = std::__find_end_impl<_RangeAlgPolicy>( 65 __first1, 66 __last1, 67 __first2, 68 __last2, 69 __pred, 70 __proj1, 71 __proj2, 72 __iterator_concept<_Iter1>(), 73 __iterator_concept<_Iter2>()); 74 return {__ret.first, __ret.second}; 75 } 76 77 template <forward_range _Range1, 78 forward_range _Range2, 79 class _Pred = ranges::equal_to, 80 class _Proj1 = identity, 81 class _Proj2 = identity> 82 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> 83 _LIBCPP_HIDE_FROM_ABI constexpr 84 borrowed_subrange_t<_Range1> operator()(_Range1&& __range1, 85 _Range2&& __range2, 86 _Pred __pred = {}, 87 _Proj1 __proj1 = {}, 88 _Proj2 __proj2 = {}) const { 89 auto __ret = std::__find_end_impl<_RangeAlgPolicy>( 90 ranges::begin(__range1), 91 ranges::end(__range1), 92 ranges::begin(__range2), 93 ranges::end(__range2), 94 __pred, 95 __proj1, 96 __proj2, 97 __iterator_concept<iterator_t<_Range1>>(), 98 __iterator_concept<iterator_t<_Range2>>()); 99 return {__ret.first, __ret.second}; 100 } 101 }; 102 } // namespace __find_end 103 104 inline namespace __cpo { 105 inline constexpr auto find_end = __find_end::__fn{}; 106 } // namespace __cpo 107 } // namespace ranges 108 109 _LIBCPP_END_NAMESPACE_STD 110 111 #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 112 113 #endif // _LIBCPP___ALGORITHM_RANGES_FIND_END_H 114