[rtsan] Remove mkfifoat interceptor (#116997)
[llvm-project.git] / libcxx / include / __algorithm / find_end.h
blobfc876d872676110ef942e3d44c0fecd5597de807
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___ALGORITHM_FIND_END_OF_H
11 #define _LIBCPP___ALGORITHM_FIND_END_OF_H
13 #include <__algorithm/comp.h>
14 #include <__algorithm/iterator_operations.h>
15 #include <__config>
16 #include <__functional/identity.h>
17 #include <__iterator/iterator_traits.h>
18 #include <__iterator/next.h>
19 #include <__type_traits/invoke.h>
20 #include <__utility/pair.h>
22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23 # pragma GCC system_header
24 #endif
26 _LIBCPP_BEGIN_NAMESPACE_STD
28 template < class _AlgPolicy,
29 class _Iter1,
30 class _Sent1,
31 class _Iter2,
32 class _Sent2,
33 class _Pred,
34 class _Proj1,
35 class _Proj2>
36 _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __find_end_impl(
37 _Iter1 __first1,
38 _Sent1 __last1,
39 _Iter2 __first2,
40 _Sent2 __last2,
41 _Pred& __pred,
42 _Proj1& __proj1,
43 _Proj2& __proj2,
44 forward_iterator_tag,
45 forward_iterator_tag) {
46 // modeled after search algorithm
47 _Iter1 __match_first = _IterOps<_AlgPolicy>::next(__first1, __last1); // __last1 is the "default" answer
48 _Iter1 __match_last = __match_first;
49 if (__first2 == __last2)
50 return pair<_Iter1, _Iter1>(__match_last, __match_last);
51 while (true) {
52 while (true) {
53 if (__first1 == __last1) // if source exhausted return last correct answer (or __last1 if never found)
54 return pair<_Iter1, _Iter1>(__match_first, __match_last);
55 if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
56 break;
57 ++__first1;
59 // *__first1 matches *__first2, now match elements after here
60 _Iter1 __m1 = __first1;
61 _Iter2 __m2 = __first2;
62 while (true) {
63 if (++__m2 == __last2) { // Pattern exhaused, record answer and search for another one
64 __match_first = __first1;
65 __match_last = ++__m1;
66 ++__first1;
67 break;
69 if (++__m1 == __last1) // Source exhausted, return last answer
70 return pair<_Iter1, _Iter1>(__match_first, __match_last);
71 // mismatch, restart with a new __first
72 if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) {
73 ++__first1;
74 break;
75 } // else there is a match, check next elements
80 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
81 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic(
82 _ForwardIterator1 __first1,
83 _ForwardIterator1 __last1,
84 _ForwardIterator2 __first2,
85 _ForwardIterator2 __last2,
86 _BinaryPredicate& __pred) {
87 auto __proj = __identity();
88 return std::__find_end_impl<_ClassicAlgPolicy>(
89 __first1,
90 __last1,
91 __first2,
92 __last2,
93 __pred,
94 __proj,
95 __proj,
96 typename iterator_traits<_ForwardIterator1>::iterator_category(),
97 typename iterator_traits<_ForwardIterator2>::iterator_category())
98 .first;
101 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
102 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end(
103 _ForwardIterator1 __first1,
104 _ForwardIterator1 __last1,
105 _ForwardIterator2 __first2,
106 _ForwardIterator2 __last2,
107 _BinaryPredicate __pred) {
108 return std::__find_end_classic(__first1, __last1, __first2, __last2, __pred);
111 template <class _ForwardIterator1, class _ForwardIterator2>
112 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
113 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
114 return std::find_end(__first1, __last1, __first2, __last2, __equal_to());
117 _LIBCPP_END_NAMESPACE_STD
119 #endif // _LIBCPP___ALGORITHM_FIND_END_OF_H