ReactOS 0.4.15-dev-7788-g1ad9096
_algobase.c File Reference
#include <stl/_algobase.h>
#include <stl/_function_base.h>
Include dependency graph for _algobase.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _IsCharLikeType< _Tp >
 
struct  _IsCharLikeType< char >
 
struct  _IsCharLikeType< unsigned char >
 
struct  _IsCharLikeType< signed char >
 

Macros

#define _STLP_ALGOBASE_C
 

Functions

template<class _InputIter1 , class _InputIter2 >
_STLP_BEGIN_NAMESPACE bool lexicographical_compare (_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2)
 
template<class _InputIter1 , class _InputIter2 , class _Compare >
bool lexicographical_compare (_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _Compare __comp)
 
template<class _InputIter1 , class _InputIter2 >
_STLP_MOVE_TO_PRIV_NAMESPACE int __lexicographical_compare_3way (_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2)
 
template<class _InputIter1 , class _InputIter2 >
_STLP_MOVE_TO_STD_NAMESPACE int lexicographical_compare_3way (_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2)
 
template<class _RandomAccessIter , class _Tp >
_STLP_MOVE_TO_PRIV_NAMESPACE _STLP_INLINE_LOOP _RandomAccessIter __find (_RandomAccessIter __first, _RandomAccessIter __last, const _Tp &__val, const random_access_iterator_tag &)
 
char__find (char *__first, char *__last, char __val, const random_access_iterator_tag &)
 
const char__find (const char *__first, const char *__last, char __val, const random_access_iterator_tag &)
 
template<class _RandomAccessIter , class _Predicate >
_STLP_INLINE_LOOP _RandomAccessIter __find_if (_RandomAccessIter __first, _RandomAccessIter __last, _Predicate __pred, const random_access_iterator_tag &)
 
template<class _InputIter , class _Tp >
_STLP_INLINE_LOOP _InputIter __find (_InputIter __first, _InputIter __last, const _Tp &__val, const input_iterator_tag &)
 
template<class _InputIter , class _Predicate >
_STLP_INLINE_LOOP _InputIter __find_if (_InputIter __first, _InputIter __last, _Predicate __pred, const input_iterator_tag &)
 
template<class _InputIter , class _Predicate >
_STLP_MOVE_TO_STD_NAMESPACE _InputIter find_if (_InputIter __first, _InputIter __last, _Predicate __pred)
 
template<class _InputIter , class _Tp >
_InputIter find (_InputIter __first, _InputIter __last, const _Tp &__val)
 
template<class _ForwardIter1 , class _ForwardIter2 , class _BinaryPred >
_ForwardIter1 search (_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 __first2, _ForwardIter2 __last2, _BinaryPred __pred)
 
template<class _Tp1 , class _Tp2 >
bool __stlp_eq (_Tp1 __val1, _Tp2 __val2)
 
template<class _InputIter , class _ForwardIter , class _Tp2 , class _Predicate >
_InputIter __find_first_of_aux2 (_InputIter __first1, _InputIter __last1, _ForwardIter __first2, _ForwardIter __last2, _Tp2 *, _Predicate __pred, const __true_type &)
 
template<class _InputIter , class _ForwardIter , class _Tp2 , class _Predicate >
_InputIter __find_first_of_aux2 (_InputIter __first1, _InputIter __last1, _ForwardIter __first2, _ForwardIter __last2, _Tp2 *, _Predicate, const __false_type &)
 
template<class _InputIter , class _ForwardIter , class _Tp1 , class _Tp2 >
_InputIter __find_first_of_aux1 (_InputIter __first1, _InputIter __last1, _ForwardIter __first2, _ForwardIter __last2, _Tp1 *__pt1, _Tp2 *__pt2)
 
template<class _InputIter , class _ForwardIter >
_InputIter __find_first_of (_InputIter __first1, _InputIter __last1, _ForwardIter __first2, _ForwardIter __last2)
 
template<class _InputIter , class _ForwardIter , class _BinaryPredicate >
_InputIter __find_first_of (_InputIter __first1, _InputIter __last1, _ForwardIter __first2, _ForwardIter __last2, _BinaryPredicate __comp)
 
template<class _ForwardIter1 , class _ForwardIter2 , class _BinaryPredicate >
_ForwardIter1 __find_end (_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 __first2, _ForwardIter2 __last2, const forward_iterator_tag &, const forward_iterator_tag &, _BinaryPredicate __comp)
 
template<class _ForwardIter1 , class _ForwardIter2 , class _BinaryPredicate >
_STLP_MOVE_TO_STD_NAMESPACE _ForwardIter1 find_end (_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 __first2, _ForwardIter2 __last2, _BinaryPredicate __comp)
 
template<class _ForwardIter , class _Tp , class _Compare1 , class _Compare2 , class _Distance >
_STLP_MOVE_TO_PRIV_NAMESPACE _ForwardIter __lower_bound (_ForwardIter __first, _ForwardIter __last, const _Tp &__val, _Compare1 __comp1, _Compare2 __comp2, _Distance *)
 

Macro Definition Documentation

◆ _STLP_ALGOBASE_C

#define _STLP_ALGOBASE_C

Definition at line 26 of file _algobase.c.

Function Documentation

◆ __find() [1/4]

template<class _InputIter , class _Tp >
_STLP_INLINE_LOOP _InputIter __find ( _InputIter  __first,
_InputIter  __last,
const _Tp &  __val,
const input_iterator_tag  
)

Definition at line 195 of file _algobase.c.

197 {
198 while (__first != __last && !(*__first == __val)) ++__first;
199 return __first;
200}
_STLP_INLINE_LOOP _InputIter __last
Definition: _algo.h:68
_STLP_INLINE_LOOP _InputIter const _Tp & __val
Definition: _algobase.h:656

◆ __find() [2/4]

template<class _RandomAccessIter , class _Tp >
_STLP_MOVE_TO_PRIV_NAMESPACE _STLP_INLINE_LOOP _RandomAccessIter __find ( _RandomAccessIter  __first,
_RandomAccessIter  __last,
const _Tp &  __val,
const random_access_iterator_tag  
)

Definition at line 112 of file _algobase.c.

114 {
115 _STLP_DIFFERENCE_TYPE(_RandomAccessIter) __trip_count = (__last - __first) >> 2;
116
117 for ( ; __trip_count > 0 ; --__trip_count) {
118 if (*__first == __val) return __first;
119 ++__first;
120
121 if (*__first == __val) return __first;
122 ++__first;
123
124 if (*__first == __val) return __first;
125 ++__first;
126
127 if (*__first == __val) return __first;
128 ++__first;
129 }
130
131 switch (__last - __first) {
132 case 3:
133 if (*__first == __val) return __first;
134 ++__first;
135 case 2:
136 if (*__first == __val) return __first;
137 ++__first;
138 case 1:
139 if (*__first == __val) return __first;
140 //++__first;
141 case 0:
142 default:
143 return __last;
144 }
145}
#define _STLP_DIFFERENCE_TYPE(_Iterator)

Referenced by find().

◆ __find() [3/4]

char * __find ( char __first,
char __last,
char  __val,
const random_access_iterator_tag  
)
inline

Definition at line 148 of file _algobase.c.

148 {
149 void *res = memchr(__first, __val, __last - __first);
150 return res != 0 ? __STATIC_CAST(char*, res) : __last;
151}
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
GLuint res
Definition: glext.h:9613
#define memchr(s, c, n)
Definition: mkisofs.h:875

◆ __find() [4/4]

const char * __find ( const char __first,
const char __last,
char  __val,
const random_access_iterator_tag  
)
inline

Definition at line 153 of file _algobase.c.

153 {
154 const void *res = memchr(__first, __val, __last - __first);
155 return res != 0 ? __STATIC_CAST(const char*, res) : __last;
156}

◆ __find_end()

template<class _ForwardIter1 , class _ForwardIter2 , class _BinaryPredicate >
_ForwardIter1 __find_end ( _ForwardIter1  __first1,
_ForwardIter1  __last1,
_ForwardIter2  __first2,
_ForwardIter2  __last2,
const forward_iterator_tag ,
const forward_iterator_tag ,
_BinaryPredicate  __comp 
)

Definition at line 369 of file _algobase.c.

372 {
373 if (__first2 == __last2)
374 return __last1;
375 else {
376 _ForwardIter1 __result = __last1;
377 for (;;) {
378 _ForwardIter1 __new_result = _STLP_STD::search(__first1, __last1, __first2, __last2, __comp);
379 if (__new_result == __last1)
380 return __result;
381 else {
382 __result = __new_result;
383 __first1 = __new_result;
384 ++__first1;
385 }
386 }
387 }
388}

Referenced by find_end().

◆ __find_first_of() [1/2]

template<class _InputIter , class _ForwardIter >
_InputIter __find_first_of ( _InputIter  __first1,
_InputIter  __last1,
_ForwardIter  __first2,
_ForwardIter  __last2 
)
inline

Definition at line 339 of file _algobase.c.

340 {
341 return _STLP_PRIV __find_first_of_aux1(__first1, __last1, __first2, __last2,
342 _STLP_VALUE_TYPE(__first1, _InputIter),
343 _STLP_VALUE_TYPE(__first2, _ForwardIter));
344}
_InputIter __find_first_of_aux1(_InputIter __first1, _InputIter __last1, _ForwardIter __first2, _ForwardIter __last2, _Tp1 *__pt1, _Tp2 *__pt2)
Definition: _algobase.c:327
#define _STLP_PRIV
Definition: _dm.h:70
#define _STLP_VALUE_TYPE(_It, _Tp)

Referenced by __find_first_of_aux2(), __str_find_first_of_aux(), and find_first_of().

◆ __find_first_of() [2/2]

template<class _InputIter , class _ForwardIter , class _BinaryPredicate >
_InputIter __find_first_of ( _InputIter  __first1,
_InputIter  __last1,
_ForwardIter  __first2,
_ForwardIter  __last2,
_BinaryPredicate  __comp 
)

Definition at line 348 of file _algobase.c.

350 {
351 for ( ; __first1 != __last1; ++__first1) {
352 for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter) {
353 if (__comp(*__first1, *__iter)) {
354 return __first1;
355 }
356 }
357 }
358 return __last1;
359}

◆ __find_first_of_aux1()

template<class _InputIter , class _ForwardIter , class _Tp1 , class _Tp2 >
_InputIter __find_first_of_aux1 ( _InputIter  __first1,
_InputIter  __last1,
_ForwardIter  __first2,
_ForwardIter  __last2,
_Tp1 *  __pt1,
_Tp2 *  __pt2 
)
inline

Definition at line 327 of file _algobase.c.

329 {
330 typedef _STLP_TYPENAME _STLP_STD::_IsIntegral<_Tp1>::_Ret _IsIntegral;
332 typedef _STLP_TYPENAME _STLP_STD::_Land2<_IsIntegral, _IsCharLike>::_Ret _UseStrcspnLikeAlgo;
333 return _STLP_PRIV __find_first_of_aux2(__first1, __last1,
334 __first2, __last2,
335 __pt2, _Identity<bool>(), _UseStrcspnLikeAlgo());
336}
_InputIter __find_first_of_aux2(_InputIter __first1, _InputIter __last1, _ForwardIter __first2, _ForwardIter __last2, _Tp2 *, _Predicate __pred, const __true_type &)
Definition: _algobase.c:297
#define _STLP_TYPENAME
Definition: features.h:612

Referenced by __find_first_of().

◆ __find_first_of_aux2() [1/2]

template<class _InputIter , class _ForwardIter , class _Tp2 , class _Predicate >
_InputIter __find_first_of_aux2 ( _InputIter  __first1,
_InputIter  __last1,
_ForwardIter  __first2,
_ForwardIter  __last2,
_Tp2 *  ,
_Predicate  __pred,
const __true_type  
)
inline

Definition at line 297 of file _algobase.c.

300 {
301 unsigned char __hints[(UCHAR_MAX + 1) / CHAR_BIT];
302 memset(__hints, 0, sizeof(__hints) / sizeof(unsigned char));
303 for (; __first2 != __last2; ++__first2) {
304 unsigned char __tmp = (unsigned char)*__first2;
305 __hints[__tmp / CHAR_BIT] |= (1 << (__tmp % CHAR_BIT));
306 }
307
308 for (; __first1 != __last1; ++__first1) {
309 _Tp2 __tmp = (_Tp2)*__first1;
310 if (__stlp_eq(*__first1, __tmp) &&
311 __pred((__hints[(unsigned char)__tmp / CHAR_BIT] & (1 << ((unsigned char)__tmp % CHAR_BIT))) != 0))
312 break;
313 }
314 return __first1;
315}
_STLP_INLINE_LOOP _InputIter _Predicate __pred
Definition: _algo.h:68
bool __stlp_eq(_Tp1 __val1, _Tp2 __val2)
Definition: _algobase.c:287
unsigned char
Definition: typeof.h:29
#define CHAR_BIT
Definition: urlcache.c:62
#define UCHAR_MAX
Definition: limits.h:25
#define memset(x, y, z)
Definition: compat.h:39

Referenced by __find_first_of_aux1(), and __str_find_first_not_of_aux3().

◆ __find_first_of_aux2() [2/2]

template<class _InputIter , class _ForwardIter , class _Tp2 , class _Predicate >
_InputIter __find_first_of_aux2 ( _InputIter  __first1,
_InputIter  __last1,
_ForwardIter  __first2,
_ForwardIter  __last2,
_Tp2 *  ,
_Predicate  ,
const __false_type  
)
inline

Definition at line 318 of file _algobase.c.

321 {
322 return _STLP_PRIV __find_first_of(__first1, __last1, __first2, __last2,
323 _STLP_PRIV __equal_to(_STLP_VALUE_TYPE(__first1, _InputIter)));
324}
_InputIter __find_first_of(_InputIter __first1, _InputIter __last1, _ForwardIter __first2, _ForwardIter __last2)
Definition: _algobase.c:339
equal_to< _Tp > __equal_to(_Tp *)

◆ __find_if() [1/2]

template<class _InputIter , class _Predicate >
_STLP_INLINE_LOOP _InputIter __find_if ( _InputIter  __first,
_InputIter  __last,
_Predicate  __pred,
const input_iterator_tag  
)

Definition at line 203 of file _algobase.c.

205 {
206 while (__first != __last && !__pred(*__first))
207 ++__first;
208 return __first;
209}

◆ __find_if() [2/2]

template<class _RandomAccessIter , class _Predicate >
_STLP_INLINE_LOOP _RandomAccessIter __find_if ( _RandomAccessIter  __first,
_RandomAccessIter  __last,
_Predicate  __pred,
const random_access_iterator_tag  
)

Definition at line 159 of file _algobase.c.

161 {
162 _STLP_DIFFERENCE_TYPE(_RandomAccessIter) __trip_count = (__last - __first) >> 2;
163
164 for ( ; __trip_count > 0 ; --__trip_count) {
165 if (__pred(*__first)) return __first;
166 ++__first;
167
168 if (__pred(*__first)) return __first;
169 ++__first;
170
171 if (__pred(*__first)) return __first;
172 ++__first;
173
174 if (__pred(*__first)) return __first;
175 ++__first;
176 }
177
178 switch(__last - __first) {
179 case 3:
180 if (__pred(*__first)) return __first;
181 ++__first;
182 case 2:
183 if (__pred(*__first)) return __first;
184 ++__first;
185 case 1:
186 if (__pred(*__first)) return __first;
187 //++__first;
188 case 0:
189 default:
190 return __last;
191 }
192}

Referenced by find_if().

◆ __lexicographical_compare_3way()

template<class _InputIter1 , class _InputIter2 >
_STLP_MOVE_TO_PRIV_NAMESPACE int __lexicographical_compare_3way ( _InputIter1  __first1,
_InputIter1  __last1,
_InputIter2  __first2,
_InputIter2  __last2 
)

Definition at line 78 of file _algobase.c.

79 {
80 while (__first1 != __last1 && __first2 != __last2) {
81 if (*__first1 < *__first2) {
82 _STLP_VERBOSE_ASSERT(!(*__first2 < *__first1), _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
83 return -1;
84 }
85 if (*__first2 < *__first1)
86 return 1;
87 ++__first1;
88 ++__first2;
89 }
90 if (__first2 == __last2) {
91 return !(__first1 == __last1);
92 }
93 else {
94 return -1;
95 }
96}
#define _STLP_VERBOSE_ASSERT(expr, diagnostic)
Definition: _debug.h:439

Referenced by rope< _CharT, _Alloc >::_S_compare(), collate< char >::do_compare(), collate< wchar_t >::do_compare(), and lexicographical_compare_3way().

◆ __lower_bound()

template<class _ForwardIter , class _Tp , class _Compare1 , class _Compare2 , class _Distance >
_STLP_MOVE_TO_PRIV_NAMESPACE _ForwardIter __lower_bound ( _ForwardIter  __first,
_ForwardIter  __last,
const _Tp &  __val,
_Compare1  __comp1,
_Compare2  __comp2,
_Distance *   
)

Definition at line 453 of file _algobase.c.

454 {
455 _Distance __len = _STLP_STD::distance(__first, __last);
456 _Distance __half;
457 _ForwardIter __middle;
458
459 while (__len > 0) {
460 __half = __len >> 1;
461 __middle = __first;
462 _STLP_STD::advance(__middle, __half);
463 if (__comp1(*__middle, __val)) {
464 _STLP_VERBOSE_ASSERT(!__comp2(__val, *__middle), _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
465 __first = __middle;
466 ++__first;
467 __len = __len - __half - 1;
468 }
469 else
470 __len = __half;
471 }
472 return __first;
473}

Referenced by __equal_range(), binary_search(), and lower_bound().

◆ __stlp_eq()

template<class _Tp1 , class _Tp2 >
bool __stlp_eq ( _Tp1  __val1,
_Tp2  __val2 
)
inline

Definition at line 287 of file _algobase.c.

288{ return __val1 == __val2; }

Referenced by __find_first_of_aux2().

◆ find()

template<class _InputIter , class _Tp >
_InputIter find ( _InputIter  __first,
_InputIter  __last,
const _Tp &  __val 
)

Definition at line 221 of file _algobase.c.

221 {
222 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
223 return _STLP_PRIV __find(__first, __last, __val, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
224}
_STLP_MOVE_TO_PRIV_NAMESPACE _STLP_INLINE_LOOP _RandomAccessIter __find(_RandomAccessIter __first, _RandomAccessIter __last, const _Tp &__val, const random_access_iterator_tag &)
Definition: _algobase.c:112
#define _STLP_DEBUG_CHECK(expr)
Definition: _debug.h:440
#define _STLP_ITERATOR_CATEGORY(_It, _Tp)

◆ find_end()

template<class _ForwardIter1 , class _ForwardIter2 , class _BinaryPredicate >
_STLP_MOVE_TO_STD_NAMESPACE _ForwardIter1 find_end ( _ForwardIter1  __first1,
_ForwardIter1  __last1,
_ForwardIter2  __first2,
_ForwardIter2  __last2,
_BinaryPredicate  __comp 
)

Definition at line 434 of file _algobase.c.

436 {
437 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
438 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
439 return _STLP_PRIV __find_end(__first1, __last1, __first2, __last2,
441 _STLP_ITERATOR_CATEGORY(__first1, _ForwardIter1),
442 _STLP_ITERATOR_CATEGORY(__first2, _ForwardIter2),
443#else
446#endif
447 __comp);
448}
_ForwardIter1 __find_end(_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 __first2, _ForwardIter2 __last2, const forward_iterator_tag &, const forward_iterator_tag &, _BinaryPredicate __comp)
Definition: _algobase.c:369
#define _STLP_CLASS_PARTIAL_SPECIALIZATION
Definition: features.h:120

◆ find_if()

template<class _InputIter , class _Predicate >
_STLP_MOVE_TO_STD_NAMESPACE _InputIter find_if ( _InputIter  __first,
_InputIter  __last,
_Predicate  __pred 
)

◆ lexicographical_compare() [1/2]

template<class _InputIter1 , class _InputIter2 >
_STLP_BEGIN_NAMESPACE bool lexicographical_compare ( _InputIter1  __first1,
_InputIter1  __last1,
_InputIter2  __first2,
_InputIter2  __last2 
)

Definition at line 39 of file _algobase.c.

40 {
41 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
42 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
43 for ( ; __first1 != __last1 && __first2 != __last2
44 ; ++__first1, ++__first2) {
45 if (*__first1 < *__first2) {
46 _STLP_VERBOSE_ASSERT(!(*__first2 < *__first1), _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
47 return true;
48 }
49 if (*__first2 < *__first1)
50 return false;
51 }
52 return __first1 == __last1 && __first2 != __last2;
53}

Referenced by LexcmpTest::lexcmp1(), LexcmpTest::lexcmp2(), and operator<().

◆ lexicographical_compare() [2/2]

template<class _InputIter1 , class _InputIter2 , class _Compare >
bool lexicographical_compare ( _InputIter1  __first1,
_InputIter1  __last1,
_InputIter2  __first2,
_InputIter2  __last2,
_Compare  __comp 
)

Definition at line 56 of file _algobase.c.

58 {
59 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
60 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
61 for ( ; __first1 != __last1 && __first2 != __last2
62 ; ++__first1, ++__first2) {
63 if (__comp(*__first1, *__first2)) {
64 _STLP_VERBOSE_ASSERT(!__comp(*__first2, *__first1),
65 _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
66 return true;
67 }
68 if (__comp(*__first2, *__first1))
69 return false;
70 }
71 return __first1 == __last1 && __first2 != __last2;
72}

◆ lexicographical_compare_3way()

template<class _InputIter1 , class _InputIter2 >
_STLP_MOVE_TO_STD_NAMESPACE int lexicographical_compare_3way ( _InputIter1  __first1,
_InputIter1  __last1,
_InputIter2  __first2,
_InputIter2  __last2 
)

Definition at line 101 of file _algobase.c.

102 {
103 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
104 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
105 return _STLP_PRIV __lexicographical_compare_3way(__first1, __last1, __first2, __last2);
106}
_STLP_MOVE_TO_PRIV_NAMESPACE int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2)
Definition: _algobase.c:78

◆ search()

template<class _ForwardIter1 , class _ForwardIter2 , class _BinaryPred >
_ForwardIter1 search ( _ForwardIter1  __first1,
_ForwardIter1  __last1,
_ForwardIter2  __first2,
_ForwardIter2  __last2,
_BinaryPred  __pred 
)

Definition at line 227 of file _algobase.c.

229 {
230 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
231 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
232 // Test for empty ranges
233 if (__first1 == __last1 || __first2 == __last2)
234 return __first1;
235
236 // Test for a pattern of length 1.
237 _ForwardIter2 __p1(__first2);
238
239 if ( ++__p1 == __last2 ) {
240 while (__first1 != __last1 && !__pred(*__first1, *__first2)) {
241 ++__first1;
242 }
243 return __first1;
244 }
245
246 // General case.
247
248 for ( ; ; ) { // __first1 != __last1 will be checked below
249 while (__first1 != __last1 && !__pred(*__first1, *__first2)) {
250 ++__first1;
251 }
252 if (__first1 == __last1) {
253 return __last1;
254 }
255 _ForwardIter2 __p = __p1;
256 _ForwardIter1 __current = __first1;
257 if (++__current == __last1) return __last1;
258
259 while (__pred(*__current, *__p)) {
260 if (++__p == __last2)
261 return __first1;
262 if (++__current == __last1)
263 return __last1;
264 }
265 ++__first1;
266 }
267 return __first1;
268}