/home/ntakagi/work/STLport-5.1.5/stlport/stl/_algobase.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Copyright (c) 1996,1997
00007  * Silicon Graphics Computer Systems, Inc.
00008  *
00009  * Copyright (c) 1997
00010  * Moscow Center for SPARC Technology
00011  *
00012  * Copyright (c) 1999
00013  * Boris Fomitchev
00014  *
00015  * This material is provided "as is", with absolutely no warranty expressed
00016  * or implied. Any use is at your own risk.
00017  *
00018  * Permission to use or copy this software for any purpose is hereby granted
00019  * without fee, provided the above notices are retained on all copies.
00020  * Permission to modify the code and to distribute modified code is granted,
00021  * provided the above notices are retained, and a notice that the code was
00022  * modified is included with the above copyright notice.
00023  *
00024  */
00025 
00026 /* NOTE: This is an internal header file, included by other STL headers.
00027  *   You should not attempt to use it directly.
00028  */
00029 
00030 #ifndef _STLP_INTERNAL_ALGOBASE_H
00031 #define _STLP_INTERNAL_ALGOBASE_H
00032 
00033 #ifndef _STLP_INTERNAL_CSTDDEF
00034 #  include <stl/_cstddef.h>
00035 #endif
00036 
00037 #ifndef _STLP_INTERNAL_CSTRING
00038 #  include <stl/_cstring.h>
00039 #endif
00040 
00041 #ifndef _STLP_CLIMITS
00042 #  include <climits>
00043 #endif
00044 
00045 #ifndef _STLP_INTERNAL_CSTDLIB
00046 #  include <stl/_cstdlib.h>
00047 #endif
00048 
00049 #ifndef _STLP_INTERNAL_PAIR_H
00050 #  include <stl/_pair.h>
00051 #endif
00052 
00053 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
00054 #  include <stl/_iterator_base.h>
00055 #endif
00056 
00057 #ifndef _STLP_TYPE_TRAITS_H
00058 #  include <stl/type_traits.h>
00059 #endif
00060 
00061 _STLP_BEGIN_NAMESPACE
00062 
00063 #if defined(_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined(_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
00064 _STLP_MOVE_TO_PRIV_NAMESPACE
00065 template <class _Tp>
00066 inline void __swap_aux(_Tp& __a, _Tp& __b, const __true_type& /*SwapImplemented*/) {
00067   __a.swap(__b);
00068 }
00069 
00070 template <class _Tp>
00071 inline void __swap_aux(_Tp& __a, _Tp& __b, const __false_type& /*SwapImplemented*/) {
00072   _Tp __tmp = __a;
00073   __a = __b;
00074   __b = __tmp;
00075 }
00076 _STLP_MOVE_TO_STD_NAMESPACE
00077 #endif /* _STLP_USE_PARTIAL_SPEC_WORKAROUND */
00078 
00079 // swap and iter_swap
00080 template <class _Tp>
00081 inline void swap(_Tp& __a, _Tp& __b) {
00082 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
00083 #  if !defined(__BORLANDC__)
00084   typedef typename _SwapImplemented<_Tp>::_Ret _Implemented;
00085 #  else
00086   enum { _Is = _SwapImplemented<_Tp>::_Is };
00087   typedef typename __bool2type<_Is>::_Ret _Implemented;
00088 #  endif
00089   _STLP_PRIV __swap_aux(__a, __b, _Implemented());
00090 #else
00091   _Tp __tmp = __a;
00092   __a = __b;
00093   __b = __tmp;
00094 #endif /* _STLP_USE_PARTIAL_SPEC_WORKAROUND */
00095 }
00096 
00097 _STLP_MOVE_TO_PRIV_NAMESPACE
00098 
00099 template <class _ForwardIter1, class _ForwardIter2, class _Value>
00100 inline void __iter_swap_aux_aux(_ForwardIter1& __i1, _ForwardIter2& __i2, _Value *) {
00101   _Value tmp = *__i1;
00102   *__i1 = *__i2;
00103   *__i2 = tmp;
00104 }
00105 
00106 template <class _ForwardIter1, class _ForwardIter2>
00107 inline void __iter_swap_aux(_ForwardIter1& __i1, _ForwardIter2& __i2, const __true_type& /*OKToSwap*/) {
00108   swap(*__i1, *__i2);
00109 }
00110 
00111 template <class _ForwardIter1, class _ForwardIter2>
00112 inline void __iter_swap_aux(_ForwardIter1& __i1, _ForwardIter2& __i2, const __false_type& /*OKToSwap*/) {
00113   __iter_swap_aux_aux( __i1, __i2, _STLP_VALUE_TYPE(__i1,_ForwardIter1) );
00114 }
00115 
00116 _STLP_MOVE_TO_STD_NAMESPACE
00117 
00118 template <class _ForwardIter1, class _ForwardIter2>
00119 inline void iter_swap(_ForwardIter1 __i1, _ForwardIter2 __i2) {
00120   // swap(*__i1, *__i2);
00121   _STLP_PRIV __iter_swap_aux( __i1, __i2, _IsOKToSwap(_STLP_VALUE_TYPE(__i1, _ForwardIter1), _STLP_VALUE_TYPE(__i2, _ForwardIter2),
00122                                                       _STLP_IS_REF_TYPE_REAL_REF(__i1, _ForwardIter1),
00123                                                       _STLP_IS_REF_TYPE_REAL_REF(__i2, _ForwardIter2))._Answer());
00124 }
00125 
00126 //--------------------------------------------------
00127 // min and max
00128 
00129 #if !defined (__BORLANDC__) || defined (_STLP_USE_OWN_NAMESPACE)
00130 #  if (defined (__BORLANDC__) && (__BORLANDC__ < 0x580)) && !defined (__STDC__)
00131 //In not ANSI mode Borland import min/max in global namespace which conflict
00132 //with STLport min/max when user does a 'using namespace std' in its code
00133 //(see test/unit/alg_test.cpp). To avoid this clash we simply import Borland min/max
00134 //in STLport namespace.
00135 using _STLP_VENDOR_STD::min;
00136 using _STLP_VENDOR_STD::max;
00137 #  else
00138 template <class _Tp>
00139 inline const _Tp& (min)(const _Tp& __a, const _Tp& __b) { return __b < __a ? __b : __a; }
00140 template <class _Tp>
00141 inline const _Tp& (max)(const _Tp& __a, const _Tp& __b) {  return  __a < __b ? __b : __a; }
00142 #  endif
00143 #endif
00144 
00145 # if defined (__BORLANDC__) && defined (_STLP_USE_OWN_NAMESPACE)
00146 inline unsigned long (min) (unsigned long __a, unsigned long __b) { return __b < __a ? __b : __a; }
00147 inline unsigned long (max) (unsigned long __a, unsigned long __b) {  return  __a < __b ? __b : __a; }
00148 # endif
00149 
00150 template <class _Tp, class _Compare>
00151 inline const _Tp& (min)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
00152   return __comp(__b, __a) ? __b : __a;
00153 }
00154 
00155 template <class _Tp, class _Compare>
00156 inline const _Tp& (max)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
00157   return __comp(__a, __b) ? __b : __a;
00158 }
00159 
00160 //--------------------------------------------------
00161 // copy
00162 
00163 // All of these auxiliary functions serve two purposes.  (1) Replace
00164 // calls to copy with memmove whenever possible.  (Memmove, not memcpy,
00165 // because the input and output ranges are permitted to overlap.)
00166 // (2) If we're using random access iterators, then write the loop as
00167 // a for loop with an explicit count.
00168 
00169 _STLP_MOVE_TO_PRIV_NAMESPACE
00170 
00171 template <class _InputIter, class _OutputIter, class _Distance>
00172 inline _OutputIter __copy(_InputIter __first, _InputIter __last,
00173                           _OutputIter __result, const input_iterator_tag &, _Distance*) {
00174   for ( ; __first != __last; ++__result, ++__first)
00175     *__result = *__first;
00176   return __result;
00177 }
00178 
00179 #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
00180 template <class _InputIter, class _OutputIter, class _Distance>
00181 inline _OutputIter __copy(_InputIter __first, _InputIter __last,
00182                           _OutputIter __result, const forward_iterator_tag &, _Distance* ) {
00183   for ( ; __first != __last; ++__result, ++__first)
00184     *__result = *__first;
00185   return __result;
00186 }
00187 
00188 template <class _InputIter, class _OutputIter, class _Distance>
00189 inline _OutputIter __copy(_InputIter __first, _InputIter __last,
00190                           _OutputIter __result, const bidirectional_iterator_tag &, _Distance* ) {
00191   for ( ; __first != __last; ++__result, ++__first)
00192     *__result = *__first;
00193   return __result;
00194 }
00195 #endif
00196 
00197 template <class _RandomAccessIter, class _OutputIter, class _Distance>
00198 inline _OutputIter
00199 __copy(_RandomAccessIter __first, _RandomAccessIter __last,
00200        _OutputIter __result, const random_access_iterator_tag &, _Distance*) {
00201   for (_Distance __n = __last - __first; __n > 0; --__n) {
00202     *__result = *__first;
00203     ++__first;
00204     ++__result;
00205   }
00206   return __result;
00207 }
00208 
00209 inline void*
00210 __copy_trivial(const void* __first, const void* __last, void* __result) {
00211   size_t __n = (const char*)__last - (const char*)__first;
00212   return __n ? (void *)((char*)memmove(__result, __first, __n) + __n) : __result;
00213 }
00214 
00215 //--------------------------------------------------
00216 // copy_backward auxiliary functions
00217 
00218 template <class _BidirectionalIter1, class _BidirectionalIter2,
00219           class _Distance>
00220 inline _BidirectionalIter2 __copy_backward(_BidirectionalIter1 __first,
00221                                            _BidirectionalIter1 __last,
00222                                            _BidirectionalIter2 __result,
00223                                            const bidirectional_iterator_tag &,
00224                                            _Distance*) {
00225   while (__first != __last)
00226     *--__result = *--__last;
00227   return __result;
00228 }
00229 
00230 template <class _RandomAccessIter, class _BidirectionalIter, class _Distance>
00231 inline _BidirectionalIter __copy_backward(_RandomAccessIter __first,
00232                                           _RandomAccessIter __last,
00233                                           _BidirectionalIter __result,
00234                                           const random_access_iterator_tag &,
00235                                           _Distance*) {
00236   for (_Distance __n = __last - __first; __n > 0; --__n)
00237     *--__result = *--__last;
00238   return __result;
00239 }
00240 
00241 inline void*
00242 __copy_trivial_backward(const void* __first, const void* __last, void* __result) {
00243   const ptrdiff_t _Num = (const char*)__last - (const char*)__first;
00244   return (_Num > 0) ? memmove((char*)__result - _Num, __first, _Num) : __result ;
00245 }
00246 
00247 template <class _InputIter, class _OutputIter>
00248 inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
00249                                const __false_type& /*IsOKToMemCpy*/) {
00250   return __copy(__first, __last, __result, random_access_iterator_tag(), (ptrdiff_t*)0);
00251 }
00252 template <class _InputIter, class _OutputIter>
00253 inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
00254                                const __true_type& /*IsOKToMemCpy*/) {
00255   // we know they all pointers, so this cast is OK
00256   //  return (_OutputIter)__copy_trivial(&(*__first), &(*__last), &(*__result));
00257   return (_OutputIter)__copy_trivial(__first, __last, __result);
00258 }
00259 
00260 template <class _InputIter, class _OutputIter>
00261 inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
00262                               const __true_type& /*BothPtrType*/) {
00263   return __copy_ptrs(__first, __last, __result,
00264                      _UseTrivialCopy(_STLP_VALUE_TYPE(__first, _InputIter),
00265                                      _STLP_VALUE_TYPE(__result, _OutputIter))._Answer());
00266 }
00267 
00268 template <class _InputIter, class _OutputIter>
00269 inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
00270                               const __false_type& /*BothPtrType*/) {
00271   return __copy(__first, __last, __result,
00272                 _STLP_ITERATOR_CATEGORY(__first, _InputIter),
00273                 _STLP_DISTANCE_TYPE(__first, _InputIter));
00274 }
00275 
00276 _STLP_MOVE_TO_STD_NAMESPACE
00277 
00278 template <class _InputIter, class _OutputIter>
00279 inline _OutputIter copy(_InputIter __first, _InputIter __last, _OutputIter __result) {
00280   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00281   return _STLP_PRIV __copy_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter>::_Answer());
00282 }
00283 
00284 _STLP_MOVE_TO_PRIV_NAMESPACE
00285 
00286 template <class _InputIter, class _OutputIter>
00287 inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last,
00288                                         _OutputIter __result, const __false_type& /*TrivialAssignment*/) {
00289   return __copy_backward(__first, __last, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
00290 }
00291 template <class _InputIter, class _OutputIter>
00292 inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last,
00293                                         _OutputIter __result, const __true_type& /*TrivialAssignment*/) {
00294   return (_OutputIter)__copy_trivial_backward(__first, __last, __result);
00295 }
00296 
00297 template <class _InputIter, class _OutputIter>
00298 inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
00299   return __copy_backward(__first, __last, __result, _STLP_ITERATOR_CATEGORY(__first,_InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
00300 }
00301 
00302 template <class _InputIter, class _OutputIter>
00303 inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
00304   return __copy_backward_ptrs(__first, __last, __result,
00305                               _UseTrivialCopy(_STLP_VALUE_TYPE(__first, _InputIter),
00306                                               _STLP_VALUE_TYPE(__result, _OutputIter))._Answer());
00307 }
00308 
00309 _STLP_MOVE_TO_STD_NAMESPACE
00310 
00311 template <class _InputIter, class _OutputIter>
00312 inline _OutputIter copy_backward(_InputIter __first, _InputIter __last, _OutputIter __result) {
00313   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00314   return _STLP_PRIV __copy_backward_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter>::_Answer() );
00315 }
00316 
00317 #if !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS)
00318 #  define _STLP_DECLARE_COPY_TRIVIAL(_Tp)                                       \
00319 inline _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result)          \
00320 { return (_Tp*)__copy_trivial(__first, __last, __result); }                     \
00321 inline _Tp* copy_backward(const _Tp* __first, const _Tp* __last, _Tp* __result) \
00322 { return (_Tp*)__copy_trivial_backward(__first, __last, __result); }
00323 
00324 _STLP_DECLARE_COPY_TRIVIAL(char)
00325 #  if !defined (_STLP_NO_SIGNED_BUILTINS)
00326 _STLP_DECLARE_COPY_TRIVIAL(signed char)
00327 #  endif
00328 _STLP_DECLARE_COPY_TRIVIAL(unsigned char)
00329 _STLP_DECLARE_COPY_TRIVIAL(short)
00330 _STLP_DECLARE_COPY_TRIVIAL(unsigned short)
00331 _STLP_DECLARE_COPY_TRIVIAL(int)
00332 _STLP_DECLARE_COPY_TRIVIAL(unsigned int)
00333 _STLP_DECLARE_COPY_TRIVIAL(long)
00334 _STLP_DECLARE_COPY_TRIVIAL(unsigned long)
00335 #  if !defined(_STLP_NO_WCHAR_T) && !defined (_STLP_WCHAR_T_IS_USHORT)
00336 _STLP_DECLARE_COPY_TRIVIAL(wchar_t)
00337 #  endif
00338 #  if defined (_STLP_LONG_LONG)
00339 _STLP_DECLARE_COPY_TRIVIAL(_STLP_LONG_LONG)
00340 _STLP_DECLARE_COPY_TRIVIAL(unsigned _STLP_LONG_LONG)
00341 #  endif
00342 _STLP_DECLARE_COPY_TRIVIAL(float)
00343 _STLP_DECLARE_COPY_TRIVIAL(double)
00344 #  if !defined (_STLP_NO_LONG_DOUBLE)
00345 _STLP_DECLARE_COPY_TRIVIAL(long double)
00346 #  endif
00347 #  undef _STLP_DECLARE_COPY_TRIVIAL
00348 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
00349 
00350 //--------------------------------------------------
00351 // copy_n (not part of the C++ standard)
00352 
00353 #if !defined (_STLP_NO_EXTENSIONS)
00354 _STLP_MOVE_TO_PRIV_NAMESPACE
00355 
00356 template <class _InputIter, class _Size, class _OutputIter>
00357 _STLP_INLINE_LOOP pair<_InputIter, _OutputIter>
00358 __copy_n(_InputIter __first, _Size __count,
00359          _OutputIter __result,
00360          const input_iterator_tag &) {
00361   for ( ; __count > 0; --__count) {
00362     *__result = *__first;
00363     ++__first;
00364     ++__result;
00365   }
00366   return pair<_InputIter, _OutputIter>(__first, __result);
00367 }
00368 
00369 template <class _RAIter, class _Size, class _OutputIter>
00370 inline pair<_RAIter, _OutputIter>
00371 __copy_n(_RAIter __first, _Size __count,
00372          _OutputIter __result,
00373          const random_access_iterator_tag &) {
00374   _RAIter __last = __first + __count;
00375   return pair<_RAIter, _OutputIter>(__last, copy(__first, __last, __result));
00376 }
00377 
00378 _STLP_MOVE_TO_STD_NAMESPACE
00379 
00380 template <class _InputIter, class _Size, class _OutputIter>
00381 inline pair<_InputIter, _OutputIter>
00382 copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
00383   _STLP_FIX_LITERAL_BUG(__first)
00384   return _STLP_PRIV __copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
00385 }
00386 #endif
00387 
00388 //--------------------------------------------------
00389 // fill and fill_n
00390 template <class _ForwardIter, class _Tp>
00391 _STLP_INLINE_LOOP
00392 void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
00393   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00394   for ( ; __first != __last; ++__first)
00395     *__first = __val;
00396 }
00397 
00398 _STLP_MOVE_TO_PRIV_NAMESPACE
00399 
00400 template <class _OutputIter, class _Size, class _Tp>
00401 _STLP_INLINE_LOOP
00402 _OutputIter __fill_n(_OutputIter __first, _Size __n, const _Tp& __val) {
00403   _STLP_FIX_LITERAL_BUG(__first)
00404   for ( ; __n > 0; --__n, ++__first)
00405     *__first = __val;
00406   return __first;
00407 }
00408 
00409 _STLP_MOVE_TO_STD_NAMESPACE
00410 
00411 template <class _OutputIter, class _Size, class _Tp>
00412 _STLP_INLINE_LOOP
00413 void fill_n(_OutputIter __first, _Size __n, const _Tp& __val) {
00414   _STLP_FIX_LITERAL_BUG(__first)
00415   _STLP_PRIV __fill_n(__first, __n, __val);
00416 }
00417 
00418 // Specialization: for one-byte types we can use memset.
00419 inline void fill(unsigned char* __first, unsigned char* __last,
00420                  const unsigned char& __val) {
00421   unsigned char __tmp = __val;
00422   memset(__first, __tmp, __last - __first);
00423 }
00424 #if !defined (_STLP_NO_SIGNED_BUILTINS)
00425 inline void fill(signed char* __first, signed char* __last,
00426                  const signed char& __val) {
00427   signed char __tmp = __val;
00428   memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
00429 }
00430 #endif
00431 inline void fill(char* __first, char* __last, const char& __val) {
00432   char __tmp = __val;
00433   memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
00434 }
00435 
00436 #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
00437 _STLP_MOVE_TO_PRIV_NAMESPACE
00438 
00439 template <class _Size>
00440 inline unsigned char* __fill_n(unsigned char* __first, _Size __n,
00441                              const unsigned char& __val) {
00442   fill(__first, __first + __n, __val);
00443   return __first + __n;
00444 }
00445 
00446 template <class _Size>
00447 inline signed char* __fill_n(char* __first, _Size __n,
00448                            const signed char& __val) {
00449   fill(__first, __first + __n, __val);
00450   return __first + __n;
00451 }
00452 
00453 template <class _Size>
00454 inline char* __fill_n(char* __first, _Size __n, const char& __val) {
00455   fill(__first, __first + __n, __val);
00456   return __first + __n;
00457 }
00458 
00459 _STLP_MOVE_TO_STD_NAMESPACE
00460 #endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
00461 
00462 
00463 //--------------------------------------------------
00464 // equal and mismatch
00465 
00466 template <class _InputIter1, class _InputIter2>
00467 _STLP_INLINE_LOOP
00468 pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
00469                                         _InputIter1 __last1,
00470                                         _InputIter2 __first2) {
00471   _STLP_FIX_LITERAL_BUG(__first2)
00472   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
00473   while (__first1 != __last1 && *__first1 == *__first2) {
00474     ++__first1;
00475     ++__first2;
00476   }
00477   return pair<_InputIter1, _InputIter2>(__first1, __first2);
00478 }
00479 
00480 template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
00481 _STLP_INLINE_LOOP
00482 pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
00483                                         _InputIter1 __last1,
00484                                         _InputIter2 __first2,
00485                                         _BinaryPredicate __binary_pred) {
00486   _STLP_FIX_LITERAL_BUG(__first2)
00487   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
00488   while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) {
00489     ++__first1;
00490     ++__first2;
00491   }
00492   return pair<_InputIter1, _InputIter2>(__first1, __first2);
00493 }
00494 
00495 template <class _InputIter1, class _InputIter2>
00496 _STLP_INLINE_LOOP
00497 bool equal(_InputIter1 __first1, _InputIter1 __last1,
00498                   _InputIter2 __first2) {
00499   _STLP_FIX_LITERAL_BUG(__first1) _STLP_FIX_LITERAL_BUG(__last1)  _STLP_FIX_LITERAL_BUG(__first2)
00500   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
00501   for ( ; __first1 != __last1; ++__first1, ++__first2)
00502     if (!(*__first1 == *__first2))
00503       return false;
00504   return true;
00505 }
00506 
00507 template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
00508 _STLP_INLINE_LOOP
00509 bool equal(_InputIter1 __first1, _InputIter1 __last1,
00510                   _InputIter2 __first2, _BinaryPredicate __binary_pred) {
00511   _STLP_FIX_LITERAL_BUG(__first2)
00512   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
00513   for ( ; __first1 != __last1; ++__first1, ++__first2)
00514     if (!__binary_pred(*__first1, *__first2))
00515       return false;
00516   return true;
00517 }
00518 
00519 //--------------------------------------------------
00520 // lexicographical_compare and lexicographical_compare_3way.
00521 // (the latter is not part of the C++ standard.)
00522 
00523 template <class _InputIter1, class _InputIter2>
00524 bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
00525                              _InputIter2 __first2, _InputIter2 __last2);
00526 
00527 template <class _InputIter1, class _InputIter2, class _Compare>
00528 bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
00529                              _InputIter2 __first2, _InputIter2 __last2,
00530                              _Compare __comp);
00531 
00532 inline bool
00533 lexicographical_compare(const unsigned char* __first1,
00534                         const unsigned char* __last1,
00535                         const unsigned char* __first2,
00536                         const unsigned char* __last2) {
00537   const size_t __len1 = __last1 - __first1;
00538   const size_t __len2 = __last2 - __first2;
00539   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
00540   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
00541 
00542   const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
00543   return __result != 0 ? (__result < 0) : (__len1 < __len2);
00544 }
00545 
00546 
00547 #if !(CHAR_MAX == SCHAR_MAX)
00548 inline bool lexicographical_compare(const char* __first1, const char* __last1,
00549                                     const char* __first2, const char* __last2) {
00550   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
00551   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
00552 
00553   return lexicographical_compare((const unsigned char*) __first1,
00554                                  (const unsigned char*) __last1,
00555                                  (const unsigned char*) __first2,
00556                                  (const unsigned char*) __last2);
00557 }
00558 #endif /* CHAR_MAX == SCHAR_MAX */
00559 
00560 _STLP_MOVE_TO_PRIV_NAMESPACE
00561 
00562 template <class _InputIter1, class _InputIter2>
00563 int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
00564                                    _InputIter2 __first2, _InputIter2 __last2);
00565 
00566 inline int
00567 __lexicographical_compare_3way(const unsigned char* __first1,
00568                                const unsigned char* __last1,
00569                                const unsigned char* __first2,
00570                                const unsigned char* __last2) {
00571   const ptrdiff_t __len1 = __last1 - __first1;
00572   const ptrdiff_t __len2 = __last2 - __first2;
00573   const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
00574   return __result != 0 ? __result
00575                        : (__len1 == __len2 ? 0 : (__len1 < __len2 ? -1 : 1));
00576 }
00577 
00578 
00579 #if !(CHAR_MAX == SCHAR_MAX)
00580 inline int
00581 __lexicographical_compare_3way(const char* __first1, const char* __last1,
00582                                const char* __first2, const char* __last2) {
00583   return __lexicographical_compare_3way((const unsigned char*) __first1,
00584                                         (const unsigned char*) __last1,
00585                                         (const unsigned char*) __first2,
00586                                         (const unsigned char*) __last2);
00587 }
00588 #endif
00589 
00590 _STLP_MOVE_TO_STD_NAMESPACE
00591 
00592 #if !defined (_STLP_NO_EXTENSIONS)
00593 template <class _InputIter1, class _InputIter2>
00594 int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
00595                                  _InputIter2 __first2, _InputIter2 __last2);
00596 
00597 #endif /* EXTENSIONS */
00598 
00599 // count
00600 template <class _InputIter, class _Tp>
00601 _STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
00602 count(_InputIter __first, _InputIter __last, const _Tp& __val) {
00603   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00604   _STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
00605   for ( ; __first != __last; ++__first)
00606     if (*__first == __val)
00607       ++__n;
00608   return __n;
00609 }
00610 
00611 // find and find_if. Note find may be expressed in terms of find_if if appropriate binder was available.
00612 template <class _InputIter, class _Tp>
00613 _InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val);
00614 
00615 template <class _InputIter, class _Predicate>
00616 _InputIter find_if(_InputIter __first, _InputIter __last, _Predicate __pred);
00617 
00618 // search.
00619 template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
00620 _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
00621                      _ForwardIter2 __first2, _ForwardIter2 __last2, _BinaryPred  __predicate);
00622 
00623 _STLP_MOVE_TO_PRIV_NAMESPACE
00624 
00625 // find_first_of
00626 template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
00627 _InputIter __find_first_of(_InputIter __first1, _InputIter __last1,
00628                            _ForwardIter __first2, _ForwardIter __last2,
00629                            _BinaryPredicate __comp);
00630 
00631 _STLP_MOVE_TO_STD_NAMESPACE
00632 
00633 template <class _ForwardIter1, class _ForwardIter2,
00634           class _BinaryPredicate>
00635 _ForwardIter1
00636 find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
00637          _ForwardIter2 __first2, _ForwardIter2 __last2,
00638          _BinaryPredicate __comp);
00639 
00640 // replace
00641 template <class _ForwardIter, class _Tp>
00642 _STLP_INLINE_LOOP void
00643 replace(_ForwardIter __first, _ForwardIter __last,
00644         const _Tp& __old_value, const _Tp& __new_value) {
00645   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00646   for ( ; __first != __last; ++__first)
00647     if (*__first == __old_value)
00648       *__first = __new_value;
00649 }
00650 
00651 _STLP_MOVE_TO_PRIV_NAMESPACE
00652 
00653 template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
00654 _ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
00655                            const _Tp& __val, _Compare1 __comp1, _Compare2 __comp2, _Distance*);
00656 
00657 _STLP_MOVE_TO_STD_NAMESPACE
00658 
00659 _STLP_END_NAMESPACE
00660 
00661 #if !defined (_STLP_LINK_TIME_INSTANTIATION)
00662 #  include <stl/_algobase.c>
00663 #endif
00664 
00665 #endif /* _STLP_INTERNAL_ALGOBASE_H */
00666 
00667 // Local Variables:
00668 // mode:C++
00669 // End:
00670 



Generated on Mon Mar 10 15:32:18 2008 by  doxygen 1.5.1