4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
18 * Permission to use or copy this software for any purpose is hereby granted
19 * without fee, provided the above notices are retained on all copies.
20 * Permission to modify the code and to distribute modified code is granted,
21 * provided the above notices are retained, and a notice that the code was
22 * modified is included with the above copyright notice.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_ALGOBASE_H
31 #define _STLP_INTERNAL_ALGOBASE_H
33 #ifndef _STLP_INTERNAL_CSTDDEF
34 # include <stl/_cstddef.h>
37 #ifndef _STLP_INTERNAL_CSTRING
38 # include <stl/_cstring.h>
45 #ifndef _STLP_INTERNAL_CSTDLIB
46 # include <stl/_cstdlib.h>
49 #ifndef _STLP_INTERNAL_PAIR_H
50 # include <stl/_pair.h>
53 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
54 # include <stl/_iterator_base.h>
57 #ifndef _STLP_TYPE_TRAITS_H
58 # include <stl/type_traits.h>
63 #if defined(_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined(_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
64 _STLP_MOVE_TO_PRIV_NAMESPACE
66 inline void __swap_aux(_Tp& __a, _Tp& __b, const __true_type& /*SwapImplemented*/) {
71 inline void __swap_aux(_Tp& __a, _Tp& __b, const __false_type& /*SwapImplemented*/) {
76 _STLP_MOVE_TO_STD_NAMESPACE
77 #endif /* _STLP_USE_PARTIAL_SPEC_WORKAROUND */
81 inline void swap(_Tp& __a, _Tp& __b) {
82 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
83 # if !defined(__BORLANDC__)
84 typedef typename _SwapImplemented<_Tp>::_Ret _Implemented;
86 enum { _Is = _SwapImplemented<_Tp>::_Is };
87 typedef typename __bool2type<_Is>::_Ret _Implemented;
89 _STLP_PRIV __swap_aux(__a, __b, _Implemented());
94 #endif /* _STLP_USE_PARTIAL_SPEC_WORKAROUND */
97 _STLP_MOVE_TO_PRIV_NAMESPACE
99 template <class _ForwardIter1, class _ForwardIter2, class _Value>
100 inline void __iter_swap_aux_aux(_ForwardIter1& __i1, _ForwardIter2& __i2, _Value *) {
106 template <class _ForwardIter1, class _ForwardIter2>
107 inline void __iter_swap_aux(_ForwardIter1& __i1, _ForwardIter2& __i2, const __true_type& /*OKToSwap*/) {
111 template <class _ForwardIter1, class _ForwardIter2>
112 inline void __iter_swap_aux(_ForwardIter1& __i1, _ForwardIter2& __i2, const __false_type& /*OKToSwap*/) {
113 __iter_swap_aux_aux( __i1, __i2, _STLP_VALUE_TYPE(__i1,_ForwardIter1) );
116 _STLP_MOVE_TO_STD_NAMESPACE
118 template <class _ForwardIter1, class _ForwardIter2>
119 inline void iter_swap(_ForwardIter1 __i1, _ForwardIter2 __i2) {
120 // swap(*__i1, *__i2);
121 _STLP_PRIV __iter_swap_aux( __i1, __i2, _IsOKToSwap(_STLP_VALUE_TYPE(__i1, _ForwardIter1), _STLP_VALUE_TYPE(__i2, _ForwardIter2),
122 _STLP_IS_REF_TYPE_REAL_REF(__i1, _ForwardIter1),
123 _STLP_IS_REF_TYPE_REAL_REF(__i2, _ForwardIter2))._Answer());
126 //--------------------------------------------------
129 #if !defined (__BORLANDC__) || defined (_STLP_USE_OWN_NAMESPACE)
130 # if (defined (__BORLANDC__) && (__BORLANDC__ < 0x580)) && !defined (__STDC__)
131 //In not ANSI mode Borland import min/max in global namespace which conflict
132 //with STLport min/max when user does a 'using namespace std' in its code
133 //(see test/unit/alg_test.cpp). To avoid this clash we simply import Borland min/max
134 //in STLport namespace.
135 using _STLP_VENDOR_STD::min;
136 using _STLP_VENDOR_STD::max;
139 inline const _Tp& (min)(const _Tp& __a, const _Tp& __b) { return __b < __a ? __b : __a; }
141 inline const _Tp& (max)(const _Tp& __a, const _Tp& __b) { return __a < __b ? __b : __a; }
145 # if defined (__BORLANDC__) && defined (_STLP_USE_OWN_NAMESPACE)
146 inline unsigned long (min) (unsigned long __a, unsigned long __b) { return __b < __a ? __b : __a; }
147 inline unsigned long (max) (unsigned long __a, unsigned long __b) { return __a < __b ? __b : __a; }
150 template <class _Tp, class _Compare>
151 inline const _Tp& (min)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
152 return __comp(__b, __a) ? __b : __a;
155 template <class _Tp, class _Compare>
156 inline const _Tp& (max)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
157 return __comp(__a, __b) ? __b : __a;
160 //--------------------------------------------------
163 // All of these auxiliary functions serve two purposes. (1) Replace
164 // calls to copy with memmove whenever possible. (Memmove, not memcpy,
165 // because the input and output ranges are permitted to overlap.)
166 // (2) If we're using random access iterators, then write the loop as
167 // a for loop with an explicit count.
169 _STLP_MOVE_TO_PRIV_NAMESPACE
171 template <class _InputIter, class _OutputIter, class _Distance>
172 inline _OutputIter __copy(_InputIter __first, _InputIter __last,
173 _OutputIter __result, const input_iterator_tag &, _Distance*) {
174 for ( ; __first != __last; ++__result, ++__first)
175 *__result = *__first;
179 #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
180 template <class _InputIter, class _OutputIter, class _Distance>
181 inline _OutputIter __copy(_InputIter __first, _InputIter __last,
182 _OutputIter __result, const forward_iterator_tag &, _Distance* ) {
183 for ( ; __first != __last; ++__result, ++__first)
184 *__result = *__first;
188 template <class _InputIter, class _OutputIter, class _Distance>
189 inline _OutputIter __copy(_InputIter __first, _InputIter __last,
190 _OutputIter __result, const bidirectional_iterator_tag &, _Distance* ) {
191 for ( ; __first != __last; ++__result, ++__first)
192 *__result = *__first;
197 template <class _RandomAccessIter, class _OutputIter, class _Distance>
199 __copy(_RandomAccessIter __first, _RandomAccessIter __last,
200 _OutputIter __result, const random_access_iterator_tag &, _Distance*) {
201 for (_Distance __n = __last - __first; __n > 0; --__n) {
202 *__result = *__first;
210 __copy_trivial(const void* __first, const void* __last, void* __result) {
211 size_t __n = (const char*)__last - (const char*)__first;
212 return __n ? (void *)((char*)memmove(__result, __first, __n) + __n) : __result;
215 //--------------------------------------------------
216 // copy_backward auxiliary functions
218 template <class _BidirectionalIter1, class _BidirectionalIter2,
220 inline _BidirectionalIter2 __copy_backward(_BidirectionalIter1 __first,
221 _BidirectionalIter1 __last,
222 _BidirectionalIter2 __result,
223 const bidirectional_iterator_tag &,
225 while (__first != __last)
226 *--__result = *--__last;
230 template <class _RandomAccessIter, class _BidirectionalIter, class _Distance>
231 inline _BidirectionalIter __copy_backward(_RandomAccessIter __first,
232 _RandomAccessIter __last,
233 _BidirectionalIter __result,
234 const random_access_iterator_tag &,
236 for (_Distance __n = __last - __first; __n > 0; --__n)
237 *--__result = *--__last;
242 __copy_trivial_backward(const void* __first, const void* __last, void* __result) {
243 const ptrdiff_t _Num = (const char*)__last - (const char*)__first;
244 return (_Num > 0) ? memmove((char*)__result - _Num, __first, _Num) : __result ;
247 template <class _InputIter, class _OutputIter>
248 inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
249 const __false_type& /*IsOKToMemCpy*/) {
250 return __copy(__first, __last, __result, random_access_iterator_tag(), (ptrdiff_t*)0);
252 template <class _InputIter, class _OutputIter>
253 inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
254 const __true_type& /*IsOKToMemCpy*/) {
255 // we know they all pointers, so this cast is OK
256 // return (_OutputIter)__copy_trivial(&(*__first), &(*__last), &(*__result));
257 return (_OutputIter)__copy_trivial(__first, __last, __result);
260 template <class _InputIter, class _OutputIter>
261 inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
262 const __true_type& /*BothPtrType*/) {
263 return __copy_ptrs(__first, __last, __result,
264 _UseTrivialCopy(_STLP_VALUE_TYPE(__first, _InputIter),
265 _STLP_VALUE_TYPE(__result, _OutputIter))._Answer());
268 template <class _InputIter, class _OutputIter>
269 inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
270 const __false_type& /*BothPtrType*/) {
271 return __copy(__first, __last, __result,
272 _STLP_ITERATOR_CATEGORY(__first, _InputIter),
273 _STLP_DISTANCE_TYPE(__first, _InputIter));
276 _STLP_MOVE_TO_STD_NAMESPACE
278 template <class _InputIter, class _OutputIter>
279 inline _OutputIter copy(_InputIter __first, _InputIter __last, _OutputIter __result) {
280 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
281 return _STLP_PRIV __copy_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter>::_Answer());
284 _STLP_MOVE_TO_PRIV_NAMESPACE
286 template <class _InputIter, class _OutputIter>
287 inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last,
288 _OutputIter __result, const __false_type& /*TrivialAssignment*/) {
289 return __copy_backward(__first, __last, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
291 template <class _InputIter, class _OutputIter>
292 inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last,
293 _OutputIter __result, const __true_type& /*TrivialAssignment*/) {
294 return (_OutputIter)__copy_trivial_backward(__first, __last, __result);
297 template <class _InputIter, class _OutputIter>
298 inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
299 return __copy_backward(__first, __last, __result, _STLP_ITERATOR_CATEGORY(__first,_InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
302 template <class _InputIter, class _OutputIter>
303 inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
304 return __copy_backward_ptrs(__first, __last, __result,
305 _UseTrivialCopy(_STLP_VALUE_TYPE(__first, _InputIter),
306 _STLP_VALUE_TYPE(__result, _OutputIter))._Answer());
309 _STLP_MOVE_TO_STD_NAMESPACE
311 template <class _InputIter, class _OutputIter>
312 inline _OutputIter copy_backward(_InputIter __first, _InputIter __last, _OutputIter __result) {
313 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
314 return _STLP_PRIV __copy_backward_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter>::_Answer() );
317 #if !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS)
318 # define _STLP_DECLARE_COPY_TRIVIAL(_Tp) \
319 inline _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) \
320 { return (_Tp*)__copy_trivial(__first, __last, __result); } \
321 inline _Tp* copy_backward(const _Tp* __first, const _Tp* __last, _Tp* __result) \
322 { return (_Tp*)__copy_trivial_backward(__first, __last, __result); }
324 _STLP_DECLARE_COPY_TRIVIAL(char)
325 # if !defined (_STLP_NO_SIGNED_BUILTINS)
326 _STLP_DECLARE_COPY_TRIVIAL(signed char)
328 _STLP_DECLARE_COPY_TRIVIAL(unsigned char)
329 _STLP_DECLARE_COPY_TRIVIAL(short)
330 _STLP_DECLARE_COPY_TRIVIAL(unsigned short)
331 _STLP_DECLARE_COPY_TRIVIAL(int)
332 _STLP_DECLARE_COPY_TRIVIAL(unsigned int)
333 _STLP_DECLARE_COPY_TRIVIAL(long)
334 _STLP_DECLARE_COPY_TRIVIAL(unsigned long)
335 # if !defined(_STLP_NO_WCHAR_T) && !defined (_STLP_WCHAR_T_IS_USHORT)
336 _STLP_DECLARE_COPY_TRIVIAL(wchar_t)
338 # if defined (_STLP_LONG_LONG)
339 _STLP_DECLARE_COPY_TRIVIAL(_STLP_LONG_LONG)
340 _STLP_DECLARE_COPY_TRIVIAL(unsigned _STLP_LONG_LONG)
342 _STLP_DECLARE_COPY_TRIVIAL(float)
343 _STLP_DECLARE_COPY_TRIVIAL(double)
344 # if !defined (_STLP_NO_LONG_DOUBLE)
345 _STLP_DECLARE_COPY_TRIVIAL(long double)
347 # undef _STLP_DECLARE_COPY_TRIVIAL
348 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
350 //--------------------------------------------------
351 // copy_n (not part of the C++ standard)
353 #if !defined (_STLP_NO_EXTENSIONS)
354 _STLP_MOVE_TO_PRIV_NAMESPACE
356 template <class _InputIter, class _Size, class _OutputIter>
357 _STLP_INLINE_LOOP pair<_InputIter, _OutputIter>
358 __copy_n(_InputIter __first, _Size __count,
359 _OutputIter __result,
360 const input_iterator_tag &) {
361 for ( ; __count > 0; --__count) {
362 *__result = *__first;
366 return pair<_InputIter, _OutputIter>(__first, __result);
369 template <class _RAIter, class _Size, class _OutputIter>
370 inline pair<_RAIter, _OutputIter>
371 __copy_n(_RAIter __first, _Size __count,
372 _OutputIter __result,
373 const random_access_iterator_tag &) {
374 _RAIter __last = __first + __count;
375 return pair<_RAIter, _OutputIter>(__last, copy(__first, __last, __result));
378 _STLP_MOVE_TO_STD_NAMESPACE
380 template <class _InputIter, class _Size, class _OutputIter>
381 inline pair<_InputIter, _OutputIter>
382 copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
383 _STLP_FIX_LITERAL_BUG(__first)
384 return _STLP_PRIV __copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
388 //--------------------------------------------------
390 template <class _ForwardIter, class _Tp>
392 void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
393 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
394 for ( ; __first != __last; ++__first)
398 _STLP_MOVE_TO_PRIV_NAMESPACE
400 template <class _OutputIter, class _Size, class _Tp>
402 _OutputIter __fill_n(_OutputIter __first, _Size __n, const _Tp& __val) {
403 _STLP_FIX_LITERAL_BUG(__first)
404 for ( ; __n > 0; --__n, ++__first)
409 _STLP_MOVE_TO_STD_NAMESPACE
411 template <class _OutputIter, class _Size, class _Tp>
413 void fill_n(_OutputIter __first, _Size __n, const _Tp& __val) {
414 _STLP_FIX_LITERAL_BUG(__first)
415 _STLP_PRIV __fill_n(__first, __n, __val);
418 // Specialization: for one-byte types we can use memset.
419 inline void fill(unsigned char* __first, unsigned char* __last,
420 const unsigned char& __val) {
421 unsigned char __tmp = __val;
422 memset(__first, __tmp, __last - __first);
424 #if !defined (_STLP_NO_SIGNED_BUILTINS)
425 inline void fill(signed char* __first, signed char* __last,
426 const signed char& __val) {
427 signed char __tmp = __val;
428 memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
431 inline void fill(char* __first, char* __last, const char& __val) {
433 memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
436 #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
437 _STLP_MOVE_TO_PRIV_NAMESPACE
439 template <class _Size>
440 inline unsigned char* __fill_n(unsigned char* __first, _Size __n,
441 const unsigned char& __val) {
442 fill(__first, __first + __n, __val);
443 return __first + __n;
446 template <class _Size>
447 inline signed char* __fill_n(char* __first, _Size __n,
448 const signed char& __val) {
449 fill(__first, __first + __n, __val);
450 return __first + __n;
453 template <class _Size>
454 inline char* __fill_n(char* __first, _Size __n, const char& __val) {
455 fill(__first, __first + __n, __val);
456 return __first + __n;
459 _STLP_MOVE_TO_STD_NAMESPACE
460 #endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
463 //--------------------------------------------------
464 // equal and mismatch
466 template <class _InputIter1, class _InputIter2>
468 pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
470 _InputIter2 __first2) {
471 _STLP_FIX_LITERAL_BUG(__first2)
472 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
473 while (__first1 != __last1 && *__first1 == *__first2) {
477 return pair<_InputIter1, _InputIter2>(__first1, __first2);
480 template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
482 pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
484 _InputIter2 __first2,
485 _BinaryPredicate __binary_pred) {
486 _STLP_FIX_LITERAL_BUG(__first2)
487 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
488 while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) {
492 return pair<_InputIter1, _InputIter2>(__first1, __first2);
495 template <class _InputIter1, class _InputIter2>
497 bool equal(_InputIter1 __first1, _InputIter1 __last1,
498 _InputIter2 __first2) {
499 _STLP_FIX_LITERAL_BUG(__first1) _STLP_FIX_LITERAL_BUG(__last1) _STLP_FIX_LITERAL_BUG(__first2)
500 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
501 for ( ; __first1 != __last1; ++__first1, ++__first2)
502 if (!(*__first1 == *__first2))
507 template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
509 bool equal(_InputIter1 __first1, _InputIter1 __last1,
510 _InputIter2 __first2, _BinaryPredicate __binary_pred) {
511 _STLP_FIX_LITERAL_BUG(__first2)
512 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
513 for ( ; __first1 != __last1; ++__first1, ++__first2)
514 if (!__binary_pred(*__first1, *__first2))
519 //--------------------------------------------------
520 // lexicographical_compare and lexicographical_compare_3way.
521 // (the latter is not part of the C++ standard.)
523 template <class _InputIter1, class _InputIter2>
524 bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
525 _InputIter2 __first2, _InputIter2 __last2);
527 template <class _InputIter1, class _InputIter2, class _Compare>
528 bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
529 _InputIter2 __first2, _InputIter2 __last2,
533 lexicographical_compare(const unsigned char* __first1,
534 const unsigned char* __last1,
535 const unsigned char* __first2,
536 const unsigned char* __last2) {
537 const size_t __len1 = __last1 - __first1;
538 const size_t __len2 = __last2 - __first2;
539 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
540 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
542 const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
543 return __result != 0 ? (__result < 0) : (__len1 < __len2);
547 #if !(CHAR_MAX == SCHAR_MAX)
548 inline bool lexicographical_compare(const char* __first1, const char* __last1,
549 const char* __first2, const char* __last2) {
550 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
551 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
553 return lexicographical_compare((const unsigned char*) __first1,
554 (const unsigned char*) __last1,
555 (const unsigned char*) __first2,
556 (const unsigned char*) __last2);
558 #endif /* CHAR_MAX == SCHAR_MAX */
560 _STLP_MOVE_TO_PRIV_NAMESPACE
562 template <class _InputIter1, class _InputIter2>
563 int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
564 _InputIter2 __first2, _InputIter2 __last2);
567 __lexicographical_compare_3way(const unsigned char* __first1,
568 const unsigned char* __last1,
569 const unsigned char* __first2,
570 const unsigned char* __last2) {
571 const ptrdiff_t __len1 = __last1 - __first1;
572 const ptrdiff_t __len2 = __last2 - __first2;
573 const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
574 return __result != 0 ? __result
575 : (__len1 == __len2 ? 0 : (__len1 < __len2 ? -1 : 1));
579 #if !(CHAR_MAX == SCHAR_MAX)
581 __lexicographical_compare_3way(const char* __first1, const char* __last1,
582 const char* __first2, const char* __last2) {
583 return __lexicographical_compare_3way((const unsigned char*) __first1,
584 (const unsigned char*) __last1,
585 (const unsigned char*) __first2,
586 (const unsigned char*) __last2);
590 _STLP_MOVE_TO_STD_NAMESPACE
592 #if !defined (_STLP_NO_EXTENSIONS)
593 template <class _InputIter1, class _InputIter2>
594 int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
595 _InputIter2 __first2, _InputIter2 __last2);
597 #endif /* EXTENSIONS */
600 template <class _InputIter, class _Tp>
601 _STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
602 count(_InputIter __first, _InputIter __last, const _Tp& __val) {
603 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
604 _STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
605 for ( ; __first != __last; ++__first)
606 if (*__first == __val)
611 // find and find_if. Note find may be expressed in terms of find_if if appropriate binder was available.
612 template <class _InputIter, class _Tp>
613 _InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val);
615 template <class _InputIter, class _Predicate>
616 _InputIter find_if(_InputIter __first, _InputIter __last, _Predicate __pred);
619 template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
620 _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
621 _ForwardIter2 __first2, _ForwardIter2 __last2, _BinaryPred __predicate);
623 _STLP_MOVE_TO_PRIV_NAMESPACE
626 template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
627 _InputIter __find_first_of(_InputIter __first1, _InputIter __last1,
628 _ForwardIter __first2, _ForwardIter __last2,
629 _BinaryPredicate __comp);
631 _STLP_MOVE_TO_STD_NAMESPACE
633 template <class _ForwardIter1, class _ForwardIter2,
634 class _BinaryPredicate>
636 find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
637 _ForwardIter2 __first2, _ForwardIter2 __last2,
638 _BinaryPredicate __comp);
641 template <class _ForwardIter, class _Tp>
642 _STLP_INLINE_LOOP void
643 replace(_ForwardIter __first, _ForwardIter __last,
644 const _Tp& __old_value, const _Tp& __new_value) {
645 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
646 for ( ; __first != __last; ++__first)
647 if (*__first == __old_value)
648 *__first = __new_value;
651 _STLP_MOVE_TO_PRIV_NAMESPACE
653 template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
654 _ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
655 const _Tp& __val, _Compare1 __comp1, _Compare2 __comp2, _Distance*);
657 _STLP_MOVE_TO_STD_NAMESPACE
661 #if !defined (_STLP_LINK_TIME_INSTANTIATION)
662 # include <stl/_algobase.c>
665 #endif /* _STLP_INTERNAL_ALGOBASE_H */