Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygen_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._M_swap_workaround(__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 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 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 /* namespace specification breaks access to the right swap template overload (at least for gcc) */ 00109 /*_STLP_STD::*/ swap(*__i1, *__i2); 00110 } 00111 00112 template <class _ForwardIter1, class _ForwardIter2> 00113 inline void __iter_swap_aux(_ForwardIter1& __i1, _ForwardIter2& __i2, const __false_type& /*OKToSwap*/) { 00114 _STLP_PRIV __iter_swap_aux_aux( __i1, __i2, _STLP_VALUE_TYPE(__i1,_ForwardIter1) ); 00115 } 00116 00117 _STLP_MOVE_TO_STD_NAMESPACE 00118 00119 template <class _ForwardIter1, class _ForwardIter2> 00120 inline void iter_swap(_ForwardIter1 __i1, _ForwardIter2 __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 # if !defined (__BORLANDC__) || (__BORLANDC__ < 0x590) 00151 template <class _Tp, class _Compare> 00152 inline const _Tp& (min)(const _Tp& __a, const _Tp& __b, _Compare __comp) { 00153 return __comp(__b, __a) ? __b : __a; 00154 } 00155 00156 template <class _Tp, class _Compare> 00157 inline const _Tp& (max)(const _Tp& __a, const _Tp& __b, _Compare __comp) { 00158 return __comp(__a, __b) ? __b : __a; 00159 } 00160 # else 00161 template <class _Tp, class _Compare> 00162 inline const _Tp (min)(const _Tp __a, const _Tp __b, _Compare __comp) { 00163 return __comp(__b, __a) ? __b : __a; 00164 } 00165 00166 template <class _Tp, class _Compare> 00167 inline const _Tp (max)(const _Tp __a, const _Tp __b, _Compare __comp) { 00168 return __comp(__a, __b) ? __b : __a; 00169 } 00170 # endif 00171 00172 //-------------------------------------------------- 00173 // copy 00174 00175 // All of these auxiliary functions serve two purposes. (1) Replace 00176 // calls to copy with memmove whenever possible. (Memmove, not memcpy, 00177 // because the input and output ranges are permitted to overlap.) 00178 // (2) If we're using random access iterators, then write the loop as 00179 // a for loop with an explicit count. 00180 00181 _STLP_MOVE_TO_PRIV_NAMESPACE 00182 00183 template <class _InputIter, class _OutputIter, class _Distance> 00184 inline _OutputIter __copy(_InputIter __first, _InputIter __last, 00185 _OutputIter __result, const input_iterator_tag &, _Distance*) { 00186 for ( ; __first != __last; ++__result, ++__first) 00187 *__result = *__first; 00188 return __result; 00189 } 00190 00191 #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG) 00192 template <class _InputIter, class _OutputIter, class _Distance> 00193 inline _OutputIter __copy(_InputIter __first, _InputIter __last, 00194 _OutputIter __result, const forward_iterator_tag &, _Distance* ) { 00195 for ( ; __first != __last; ++__result, ++__first) 00196 *__result = *__first; 00197 return __result; 00198 } 00199 00200 template <class _InputIter, class _OutputIter, class _Distance> 00201 inline _OutputIter __copy(_InputIter __first, _InputIter __last, 00202 _OutputIter __result, const bidirectional_iterator_tag &, _Distance* ) { 00203 for ( ; __first != __last; ++__result, ++__first) 00204 *__result = *__first; 00205 return __result; 00206 } 00207 #endif 00208 00209 template <class _RandomAccessIter, class _OutputIter, class _Distance> 00210 inline _OutputIter 00211 __copy(_RandomAccessIter __first, _RandomAccessIter __last, 00212 _OutputIter __result, const random_access_iterator_tag &, _Distance*) { 00213 for (_Distance __n = __last - __first; __n > 0; --__n) { 00214 *__result = *__first; 00215 ++__first; 00216 ++__result; 00217 } 00218 return __result; 00219 } 00220 00221 inline void* 00222 __copy_trivial(const void* __first, const void* __last, void* __result) { 00223 size_t __n = (const char*)__last - (const char*)__first; 00224 return __n ? (void *)((char*)memmove(__result, __first, __n) + __n) : __result; 00225 } 00226 00227 //-------------------------------------------------- 00228 // copy_backward auxiliary functions 00229 00230 template <class _BidirectionalIter1, class _BidirectionalIter2, 00231 class _Distance> 00232 inline _BidirectionalIter2 __copy_backward(_BidirectionalIter1 __first, 00233 _BidirectionalIter1 __last, 00234 _BidirectionalIter2 __result, 00235 const bidirectional_iterator_tag &, 00236 _Distance*) { 00237 while (__first != __last) 00238 *--__result = *--__last; 00239 return __result; 00240 } 00241 00242 template <class _RandomAccessIter, class _BidirectionalIter, class _Distance> 00243 inline _BidirectionalIter __copy_backward(_RandomAccessIter __first, 00244 _RandomAccessIter __last, 00245 _BidirectionalIter __result, 00246 const random_access_iterator_tag &, 00247 _Distance*) { 00248 for (_Distance __n = __last - __first; __n > 0; --__n) 00249 *--__result = *--__last; 00250 return __result; 00251 } 00252 00253 inline void* 00254 __copy_trivial_backward(const void* __first, const void* __last, void* __result) { 00255 const ptrdiff_t _Num = (const char*)__last - (const char*)__first; 00256 return (_Num > 0) ? memmove((char*)__result - _Num, __first, _Num) : __result ; 00257 } 00258 00259 template <class _InputIter, class _OutputIter> 00260 inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, 00261 const __false_type& /*IsOKToMemCpy*/) { 00262 return _STLP_PRIV __copy(__first, __last, __result, random_access_iterator_tag(), (ptrdiff_t*)0); 00263 } 00264 template <class _InputIter, class _OutputIter> 00265 inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, 00266 const __true_type& /*IsOKToMemCpy*/) { 00267 // we know they all pointers, so this cast is OK 00268 // return (_OutputIter)__copy_trivial(&(*__first), &(*__last), &(*__result)); 00269 return (_OutputIter)_STLP_PRIV __copy_trivial(__first, __last, __result); 00270 } 00271 00272 template <class _InputIter, class _OutputIter> 00273 inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result, 00274 const __true_type& /*BothPtrType*/) { 00275 return _STLP_PRIV __copy_ptrs(__first, __last, __result, 00276 _UseTrivialCopy(_STLP_VALUE_TYPE(__first, _InputIter), 00277 _STLP_VALUE_TYPE(__result, _OutputIter))._Answer()); 00278 } 00279 00280 template <class _InputIter, class _OutputIter> 00281 inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result, 00282 const __false_type& /*BothPtrType*/) { 00283 return _STLP_PRIV __copy(__first, __last, __result, 00284 _STLP_ITERATOR_CATEGORY(__first, _InputIter), 00285 _STLP_DISTANCE_TYPE(__first, _InputIter)); 00286 } 00287 00288 _STLP_MOVE_TO_STD_NAMESPACE 00289 00290 template <class _InputIter, class _OutputIter> 00291 inline _OutputIter copy(_InputIter __first, _InputIter __last, _OutputIter __result) { 00292 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last)) 00293 return _STLP_PRIV __copy_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter>::_Answer()); 00294 } 00295 00296 _STLP_MOVE_TO_PRIV_NAMESPACE 00297 00298 template <class _InputIter, class _OutputIter> 00299 inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last, 00300 _OutputIter __result, const __false_type& /*TrivialAssignment*/) { 00301 return _STLP_PRIV __copy_backward(__first, __last, __result, 00302 _STLP_ITERATOR_CATEGORY(__first, _InputIter), 00303 _STLP_DISTANCE_TYPE(__first, _InputIter)); 00304 } 00305 template <class _InputIter, class _OutputIter> 00306 inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last, 00307 _OutputIter __result, const __true_type& /*TrivialAssignment*/) { 00308 return (_OutputIter)_STLP_PRIV __copy_trivial_backward(__first, __last, __result); 00309 } 00310 00311 template <class _InputIter, class _OutputIter> 00312 inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) { 00313 return _STLP_PRIV __copy_backward(__first, __last, __result, 00314 _STLP_ITERATOR_CATEGORY(__first,_InputIter), 00315 _STLP_DISTANCE_TYPE(__first, _InputIter)); 00316 } 00317 00318 template <class _InputIter, class _OutputIter> 00319 inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) { 00320 return _STLP_PRIV __copy_backward_ptrs(__first, __last, __result, 00321 _UseTrivialCopy(_STLP_VALUE_TYPE(__first, _InputIter), 00322 _STLP_VALUE_TYPE(__result, _OutputIter))._Answer()); 00323 } 00324 00325 _STLP_MOVE_TO_STD_NAMESPACE 00326 00327 template <class _InputIter, class _OutputIter> 00328 inline _OutputIter copy_backward(_InputIter __first, _InputIter __last, _OutputIter __result) { 00329 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last)) 00330 return _STLP_PRIV __copy_backward_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter>::_Answer() ); 00331 } 00332 00333 #if !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) 00334 # define _STLP_DECLARE_COPY_TRIVIAL(_Tp) \ 00335 inline _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) \ 00336 { return (_Tp*)_STLP_PRIV __copy_trivial(__first, __last, __result); } \ 00337 inline _Tp* copy_backward(const _Tp* __first, const _Tp* __last, _Tp* __result) \ 00338 { return (_Tp*)_STLP_PRIV __copy_trivial_backward(__first, __last, __result); } 00339 00340 # if !defined (_STLP_NO_BOOL) 00341 _STLP_DECLARE_COPY_TRIVIAL(bool) 00342 # endif 00343 _STLP_DECLARE_COPY_TRIVIAL(char) 00344 # if !defined (_STLP_NO_SIGNED_BUILTINS) 00345 _STLP_DECLARE_COPY_TRIVIAL(signed char) 00346 # endif 00347 _STLP_DECLARE_COPY_TRIVIAL(unsigned char) 00348 _STLP_DECLARE_COPY_TRIVIAL(short) 00349 _STLP_DECLARE_COPY_TRIVIAL(unsigned short) 00350 _STLP_DECLARE_COPY_TRIVIAL(int) 00351 _STLP_DECLARE_COPY_TRIVIAL(unsigned int) 00352 _STLP_DECLARE_COPY_TRIVIAL(long) 00353 _STLP_DECLARE_COPY_TRIVIAL(unsigned long) 00354 # if !defined(_STLP_NO_WCHAR_T) && !defined (_STLP_WCHAR_T_IS_USHORT) 00355 _STLP_DECLARE_COPY_TRIVIAL(wchar_t) 00356 # endif 00357 # if defined (_STLP_LONG_LONG) 00358 _STLP_DECLARE_COPY_TRIVIAL(_STLP_LONG_LONG) 00359 _STLP_DECLARE_COPY_TRIVIAL(unsigned _STLP_LONG_LONG) 00360 # endif 00361 _STLP_DECLARE_COPY_TRIVIAL(float) 00362 _STLP_DECLARE_COPY_TRIVIAL(double) 00363 # if !defined (_STLP_NO_LONG_DOUBLE) 00364 _STLP_DECLARE_COPY_TRIVIAL(long double) 00365 # endif 00366 # undef _STLP_DECLARE_COPY_TRIVIAL 00367 #endif 00368 00369 //-------------------------------------------------- 00370 // copy_n (not part of the C++ standard) 00371 00372 #if !defined (_STLP_NO_EXTENSIONS) 00373 _STLP_MOVE_TO_PRIV_NAMESPACE 00374 00375 template <class _InputIter, class _Size, class _OutputIter> 00376 _STLP_INLINE_LOOP _STLP_STD::pair<_InputIter, _OutputIter> 00377 __copy_n(_InputIter __first, _Size __count, _OutputIter __result, 00378 const input_iterator_tag &) { 00379 for ( ; __count > 0; --__count) { 00380 *__result = *__first; 00381 ++__first; 00382 ++__result; 00383 } 00384 return _STLP_STD::pair<_InputIter, _OutputIter>(__first, __result); 00385 } 00386 00387 template <class _RAIter, class _Size, class _OutputIter> 00388 inline _STLP_STD::pair<_RAIter, _OutputIter> 00389 __copy_n(_RAIter __first, _Size __count, _OutputIter __result, 00390 const random_access_iterator_tag &) { 00391 _RAIter __last = __first + __count; 00392 return _STLP_STD::pair<_RAIter, _OutputIter>(__last, _STLP_STD::copy(__first, __last, __result)); 00393 } 00394 00395 _STLP_MOVE_TO_STD_NAMESPACE 00396 00397 template <class _InputIter, class _Size, class _OutputIter> 00398 inline pair<_InputIter, _OutputIter> 00399 copy_n(_InputIter __first, _Size __count, _OutputIter __result) { 00400 _STLP_FIX_LITERAL_BUG(__first) 00401 return _STLP_PRIV __copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); 00402 } 00403 #endif 00404 00405 //-------------------------------------------------- 00406 // fill and fill_n 00407 _STLP_MOVE_TO_PRIV_NAMESPACE 00408 00409 template <class _ForwardIter, class _Tp> 00410 _STLP_INLINE_LOOP 00411 void __fill_fwd(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) { 00412 for ( ; __first != __last; ++__first) 00413 *__first = __val; 00414 } 00415 00416 template <class _ForwardIter, class _Tp, class _Distance> 00417 inline void __fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val, 00418 const input_iterator_tag &, _Distance*) { 00419 _STLP_PRIV __fill_fwd(__first, __last, __val); 00420 } 00421 00422 #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG) 00423 template <class _ForwardIter, class _Tp, class _Distance> 00424 _STLP_INLINE_LOOP 00425 void __fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val, 00426 const forward_iterator_tag &, _Distance*) { 00427 _STLP_PRIV __fill_fwd(__first, __last, __val); 00428 } 00429 00430 template <class _ForwardIter, class _Tp, class _Distance> 00431 _STLP_INLINE_LOOP 00432 void __fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val, 00433 const bidirectional_iterator_tag &, _Distance*) { 00434 _STLP_PRIV __fill_fwd(__first, __last, __val); 00435 } 00436 #endif 00437 00438 template <class _RandomAccessIter, class _Tp, class _Distance> 00439 _STLP_INLINE_LOOP 00440 void __fill(_RandomAccessIter __first, _RandomAccessIter __last, const _Tp& __val, 00441 const random_access_iterator_tag &, _Distance*) { 00442 for (_Distance __n = __last - __first ; __n > 0; ++__first, --__n) 00443 *__first = __val; 00444 } 00445 00446 _STLP_MOVE_TO_STD_NAMESPACE 00447 00448 template <class _ForwardIter, class _Tp> 00449 inline void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) { 00450 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last)) 00451 _STLP_PRIV __fill(__first, __last, __val, 00452 _STLP_ITERATOR_CATEGORY(__first, _ForwardIter), 00453 _STLP_DISTANCE_TYPE(__first, _ForwardIter)); 00454 } 00455 00456 // Specialization: for one-byte types we can use memset. 00457 inline void fill(unsigned char* __first, unsigned char* __last, 00458 const unsigned char& __val) { 00459 unsigned char __tmp = __val; 00460 memset(__first, __tmp, __last - __first); 00461 } 00462 #if !defined (_STLP_NO_SIGNED_BUILTINS) 00463 inline void fill(signed char* __first, signed char* __last, 00464 const signed char& __val) { 00465 signed char __tmp = __val; 00466 memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first); 00467 } 00468 #endif 00469 inline void fill(char* __first, char* __last, const char& __val) { 00470 char __tmp = __val; 00471 memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first); 00472 } 00473 00474 _STLP_MOVE_TO_PRIV_NAMESPACE 00475 00476 template <class _OutputIter, class _Size, class _Tp> 00477 _STLP_INLINE_LOOP 00478 _OutputIter __fill_n(_OutputIter __first, _Size __n, const _Tp& __val) { 00479 _STLP_FIX_LITERAL_BUG(__first) 00480 for ( ; __n > 0; --__n, ++__first) 00481 *__first = __val; 00482 return __first; 00483 } 00484 00485 #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) 00486 template <class _Size> 00487 inline unsigned char* __fill_n(unsigned char* __first, _Size __n, 00488 const unsigned char& __val) { 00489 _STLP_STD::fill(__first, __first + __n, __val); 00490 return __first + __n; 00491 } 00492 #if !defined (_STLP_NO_SIGNED_BUILTINS) 00493 template <class _Size> 00494 inline signed char* __fill_n(signed char* __first, _Size __n, 00495 const signed char& __val) { 00496 _STLP_STD::fill(__first, __first + __n, __val); 00497 return __first + __n; 00498 } 00499 #endif 00500 template <class _Size> 00501 inline char* __fill_n(char* __first, _Size __n, 00502 const char& __val) { 00503 _STLP_STD::fill(__first, __first + __n, __val); 00504 return __first + __n; 00505 } 00506 #endif 00507 00508 _STLP_MOVE_TO_STD_NAMESPACE 00509 00510 template <class _OutputIter, class _Size, class _Tp> 00511 inline void fill_n(_OutputIter __first, _Size __n, const _Tp& __val) { 00512 _STLP_FIX_LITERAL_BUG(__first) 00513 _STLP_PRIV __fill_n(__first, __n, __val); 00514 } 00515 00516 00517 //-------------------------------------------------- 00518 // equal and mismatch 00519 00520 template <class _InputIter1, class _InputIter2> 00521 _STLP_INLINE_LOOP 00522 _STLP_STD::pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1, 00523 _InputIter1 __last1, 00524 _InputIter2 __first2) { 00525 _STLP_FIX_LITERAL_BUG(__first2) 00526 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1)) 00527 while (__first1 != __last1 && *__first1 == *__first2) { 00528 ++__first1; 00529 ++__first2; 00530 } 00531 return _STLP_STD::pair<_InputIter1, _InputIter2>(__first1, __first2); 00532 } 00533 00534 template <class _InputIter1, class _InputIter2, class _BinaryPredicate> 00535 _STLP_INLINE_LOOP 00536 _STLP_STD::pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1, 00537 _InputIter1 __last1, 00538 _InputIter2 __first2, 00539 _BinaryPredicate __binary_pred) { 00540 _STLP_FIX_LITERAL_BUG(__first2) 00541 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1)) 00542 while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) { 00543 ++__first1; 00544 ++__first2; 00545 } 00546 return _STLP_STD::pair<_InputIter1, _InputIter2>(__first1, __first2); 00547 } 00548 00549 template <class _InputIter1, class _InputIter2> 00550 _STLP_INLINE_LOOP 00551 bool equal(_InputIter1 __first1, _InputIter1 __last1, 00552 _InputIter2 __first2) { 00553 _STLP_FIX_LITERAL_BUG(__first1) _STLP_FIX_LITERAL_BUG(__last1) _STLP_FIX_LITERAL_BUG(__first2) 00554 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1)) 00555 for ( ; __first1 != __last1; ++__first1, ++__first2) 00556 if (!(*__first1 == *__first2)) 00557 return false; 00558 return true; 00559 } 00560 00561 template <class _InputIter1, class _InputIter2, class _BinaryPredicate> 00562 _STLP_INLINE_LOOP 00563 bool equal(_InputIter1 __first1, _InputIter1 __last1, 00564 _InputIter2 __first2, _BinaryPredicate __binary_pred) { 00565 _STLP_FIX_LITERAL_BUG(__first2) 00566 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1)) 00567 for ( ; __first1 != __last1; ++__first1, ++__first2) 00568 if (!__binary_pred(*__first1, *__first2)) 00569 return false; 00570 return true; 00571 } 00572 00573 //-------------------------------------------------- 00574 // lexicographical_compare and lexicographical_compare_3way. 00575 // (the latter is not part of the C++ standard.) 00576 00577 template <class _InputIter1, class _InputIter2> 00578 bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1, 00579 _InputIter2 __first2, _InputIter2 __last2); 00580 00581 template <class _InputIter1, class _InputIter2, class _Compare> 00582 bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1, 00583 _InputIter2 __first2, _InputIter2 __last2, 00584 _Compare __comp); 00585 00586 inline bool 00587 lexicographical_compare(const unsigned char* __first1, 00588 const unsigned char* __last1, 00589 const unsigned char* __first2, 00590 const unsigned char* __last2) { 00591 const size_t __len1 = __last1 - __first1; 00592 const size_t __len2 = __last2 - __first2; 00593 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1)) 00594 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2)) 00595 00596 const int __result = memcmp(__first1, __first2, (min) (__len1, __len2)); 00597 return __result != 0 ? (__result < 0) : (__len1 < __len2); 00598 } 00599 00600 00601 #if !(CHAR_MAX == SCHAR_MAX) 00602 inline bool lexicographical_compare(const char* __first1, const char* __last1, 00603 const char* __first2, const char* __last2) { 00604 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1)) 00605 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2)) 00606 00607 return lexicographical_compare((const unsigned char*) __first1, 00608 (const unsigned char*) __last1, 00609 (const unsigned char*) __first2, 00610 (const unsigned char*) __last2); 00611 } 00612 #endif /* CHAR_MAX == SCHAR_MAX */ 00613 00614 _STLP_MOVE_TO_PRIV_NAMESPACE 00615 00616 template <class _InputIter1, class _InputIter2> 00617 int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1, 00618 _InputIter2 __first2, _InputIter2 __last2); 00619 00620 inline int 00621 __lexicographical_compare_3way(const unsigned char* __first1, 00622 const unsigned char* __last1, 00623 const unsigned char* __first2, 00624 const unsigned char* __last2) { 00625 const ptrdiff_t __len1 = __last1 - __first1; 00626 const ptrdiff_t __len2 = __last2 - __first2; 00627 const int __result = memcmp(__first1, __first2, (min) (__len1, __len2)); 00628 return __result != 0 ? __result 00629 : (__len1 == __len2 ? 0 : (__len1 < __len2 ? -1 : 1)); 00630 } 00631 00632 00633 #if !(CHAR_MAX == SCHAR_MAX) 00634 inline int 00635 __lexicographical_compare_3way(const char* __first1, const char* __last1, 00636 const char* __first2, const char* __last2) { 00637 return __lexicographical_compare_3way((const unsigned char*) __first1, 00638 (const unsigned char*) __last1, 00639 (const unsigned char*) __first2, 00640 (const unsigned char*) __last2); 00641 } 00642 #endif 00643 00644 _STLP_MOVE_TO_STD_NAMESPACE 00645 00646 #if !defined (_STLP_NO_EXTENSIONS) 00647 template <class _InputIter1, class _InputIter2> 00648 int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1, 00649 _InputIter2 __first2, _InputIter2 __last2); 00650 00651 #endif 00652 00653 // count 00654 template <class _InputIter, class _Tp> 00655 _STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter) 00656 count(_InputIter __first, _InputIter __last, const _Tp& __val) { 00657 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last)) 00658 _STLP_DIFFERENCE_TYPE(_InputIter) __n = 0; 00659 for ( ; __first != __last; ++__first) 00660 if (*__first == __val) 00661 ++__n; 00662 return __n; 00663 } 00664 00665 // find and find_if. Note find may be expressed in terms of find_if if appropriate binder was available. 00666 template <class _InputIter, class _Tp> 00667 _InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val); 00668 00669 template <class _InputIter, class _Predicate> 00670 _InputIter find_if(_InputIter __first, _InputIter __last, _Predicate __pred); 00671 00672 // search. 00673 template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred> 00674 _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1, 00675 _ForwardIter2 __first2, _ForwardIter2 __last2, _BinaryPred __predicate); 00676 00677 _STLP_MOVE_TO_PRIV_NAMESPACE 00678 00679 // find_first_of 00680 template <class _InputIter, class _ForwardIter> 00681 _InputIter __find_first_of(_InputIter __first1, _InputIter __last1, 00682 _ForwardIter __first2, _ForwardIter __last2); 00683 00684 template <class _InputIter, class _ForwardIter, class _BinaryPredicate> 00685 _InputIter __find_first_of(_InputIter __first1, _InputIter __last1, 00686 _ForwardIter __first2, _ForwardIter __last2, 00687 _BinaryPredicate __comp); 00688 00689 _STLP_MOVE_TO_STD_NAMESPACE 00690 00691 template <class _ForwardIter1, class _ForwardIter2, 00692 class _BinaryPredicate> 00693 _ForwardIter1 00694 find_end(_ForwardIter1 __first1, _ForwardIter1 __last1, 00695 _ForwardIter2 __first2, _ForwardIter2 __last2, 00696 _BinaryPredicate __comp); 00697 00698 // replace 00699 template <class _ForwardIter, class _Tp> 00700 _STLP_INLINE_LOOP void 00701 replace(_ForwardIter __first, _ForwardIter __last, 00702 const _Tp& __old_value, const _Tp& __new_value) { 00703 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last)) 00704 for ( ; __first != __last; ++__first) 00705 if (*__first == __old_value) 00706 *__first = __new_value; 00707 } 00708 00709 _STLP_MOVE_TO_PRIV_NAMESPACE 00710 00711 template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance> 00712 _ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last, 00713 const _Tp& __val, _Compare1 __comp1, _Compare2 __comp2, _Distance*); 00714 00715 _STLP_MOVE_TO_STD_NAMESPACE 00716 00717 _STLP_END_NAMESPACE 00718 00719 #if !defined (_STLP_LINK_TIME_INSTANTIATION) 00720 # include <stl/_algobase.c> 00721 #endif 00722 00723 #endif /* _STLP_INTERNAL_ALGOBASE_H */ 00724 00725 // Local Variables: 00726 // mode:C++ 00727 // End: 00728 Generated on Fri May 25 2012 04:27:15 for ReactOS by
1.7.6.1
|