File indexing completed on 2026-05-03 08:13:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___ALGORITHM_FIND_END_OF_H
0011 #define _LIBCPP___ALGORITHM_FIND_END_OF_H
0012
0013 #include <__algorithm/comp.h>
0014 #include <__algorithm/iterator_operations.h>
0015 #include <__config>
0016 #include <__functional/identity.h>
0017 #include <__iterator/iterator_traits.h>
0018 #include <__type_traits/invoke.h>
0019 #include <__utility/pair.h>
0020
0021 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0022 # pragma GCC system_header
0023 #endif
0024
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026
0027 template < class _AlgPolicy,
0028 class _Iter1,
0029 class _Sent1,
0030 class _Iter2,
0031 class _Sent2,
0032 class _Pred,
0033 class _Proj1,
0034 class _Proj2>
0035 _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __find_end_impl(
0036 _Iter1 __first1,
0037 _Sent1 __last1,
0038 _Iter2 __first2,
0039 _Sent2 __last2,
0040 _Pred& __pred,
0041 _Proj1& __proj1,
0042 _Proj2& __proj2,
0043 forward_iterator_tag,
0044 forward_iterator_tag) {
0045
0046 _Iter1 __match_first = _IterOps<_AlgPolicy>::next(__first1, __last1);
0047 _Iter1 __match_last = __match_first;
0048 if (__first2 == __last2)
0049 return pair<_Iter1, _Iter1>(__match_last, __match_last);
0050 while (true) {
0051 while (true) {
0052 if (__first1 == __last1)
0053 return pair<_Iter1, _Iter1>(__match_first, __match_last);
0054 if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
0055 break;
0056 ++__first1;
0057 }
0058
0059 _Iter1 __m1 = __first1;
0060 _Iter2 __m2 = __first2;
0061 while (true) {
0062 if (++__m2 == __last2) {
0063 __match_first = __first1;
0064 __match_last = ++__m1;
0065 ++__first1;
0066 break;
0067 }
0068 if (++__m1 == __last1)
0069 return pair<_Iter1, _Iter1>(__match_first, __match_last);
0070
0071 if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) {
0072 ++__first1;
0073 break;
0074 }
0075 }
0076 }
0077 }
0078
0079 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
0080 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic(
0081 _ForwardIterator1 __first1,
0082 _ForwardIterator1 __last1,
0083 _ForwardIterator2 __first2,
0084 _ForwardIterator2 __last2,
0085 _BinaryPredicate& __pred) {
0086 auto __proj = __identity();
0087 return std::__find_end_impl<_ClassicAlgPolicy>(
0088 __first1,
0089 __last1,
0090 __first2,
0091 __last2,
0092 __pred,
0093 __proj,
0094 __proj,
0095 typename iterator_traits<_ForwardIterator1>::iterator_category(),
0096 typename iterator_traits<_ForwardIterator2>::iterator_category())
0097 .first;
0098 }
0099
0100 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
0101 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end(
0102 _ForwardIterator1 __first1,
0103 _ForwardIterator1 __last1,
0104 _ForwardIterator2 __first2,
0105 _ForwardIterator2 __last2,
0106 _BinaryPredicate __pred) {
0107 return std::__find_end_classic(__first1, __last1, __first2, __last2, __pred);
0108 }
0109
0110 template <class _ForwardIterator1, class _ForwardIterator2>
0111 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
0112 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
0113 return std::find_end(__first1, __last1, __first2, __last2, __equal_to());
0114 }
0115
0116 _LIBCPP_END_NAMESPACE_STD
0117
0118 #endif