1.1 --- a/epoc32/include/stdapis/stlport/stl/_algobase.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/stdapis/stlport/stl/_algobase.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,583 @@
1.4 -_algobase.h
1.5 +/*
1.6 + *
1.7 + * Copyright (c) 1994
1.8 + * Hewlett-Packard Company
1.9 + *
1.10 + * Copyright (c) 1996,1997
1.11 + * Silicon Graphics Computer Systems, Inc.
1.12 + *
1.13 + * Copyright (c) 1997
1.14 + * Moscow Center for SPARC Technology
1.15 + *
1.16 + * Copyright (c) 1999
1.17 + * Boris Fomitchev
1.18 + *
1.19 + * This material is provided "as is", with absolutely no warranty expressed
1.20 + * or implied. Any use is at your own risk.
1.21 + *
1.22 + * Permission to use or copy this software for any purpose is hereby granted
1.23 + * without fee, provided the above notices are retained on all copies.
1.24 + * Permission to modify the code and to distribute modified code is granted,
1.25 + * provided the above notices are retained, and a notice that the code was
1.26 + * modified is included with the above copyright notice.
1.27 + *
1.28 + */
1.29 +
1.30 +/* NOTE: This is an internal header file, included by other STL headers.
1.31 + * You should not attempt to use it directly.
1.32 + */
1.33 +
1.34 +
1.35 +#ifndef _STLP_INTERNAL_ALGOBASE_H
1.36 +#define _STLP_INTERNAL_ALGOBASE_H
1.37 +
1.38 +# if ! defined (_STLP_CSTDDEF)
1.39 +# include <cstddef>
1.40 +# endif
1.41 +
1.42 +#ifndef _STLP_CSTRING
1.43 +# include <cstring>
1.44 +#endif
1.45 +
1.46 +#ifndef _STLP_CLIMITS
1.47 +# include <climits>
1.48 +#endif
1.49 +
1.50 +# if ! defined (_STLP_CSTDLIB)
1.51 +# include <cstdlib>
1.52 +# endif
1.53 +
1.54 +# ifndef _STLP_INTERNAL_PAIR_H
1.55 +# include <stl/_pair.h>
1.56 +# endif
1.57 +
1.58 +#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
1.59 +# include <stl/_iterator_base.h>
1.60 +#endif
1.61 +
1.62 +_STLP_BEGIN_NAMESPACE
1.63 +// swap and iter_swap
1.64 +template <class _Tp>
1.65 +inline void swap(_Tp& __a, _Tp& __b) {
1.66 + _Tp __tmp = __a;
1.67 + __a = __b;
1.68 + __b = __tmp;
1.69 +}
1.70 +
1.71 +template <class _ForwardIter1, class _ForwardIter2>
1.72 +inline void iter_swap(_ForwardIter1 __i1, _ForwardIter2 __i2) {
1.73 + swap(*__i1, *__i2);
1.74 +}
1.75 +
1.76 +//--------------------------------------------------
1.77 +// min and max
1.78 +
1.79 +# if !defined (__BORLANDC__) || defined (_STLP_USE_OWN_NAMESPACE)
1.80 +template <class _Tp>
1.81 +inline const _Tp& (min)(const _Tp& __a, const _Tp& __b) { return __b < __a ? __b : __a; }
1.82 +template <class _Tp>
1.83 +inline const _Tp& (max)(const _Tp& __a, const _Tp& __b) { return __a < __b ? __b : __a; }
1.84 +#endif /* __BORLANDC__ */
1.85 +
1.86 +# if defined (__BORLANDC__) && ( __BORLANDC__ < 0x530 || defined (_STLP_USE_OWN_NAMESPACE))
1.87 +inline unsigned long (min) (unsigned long __a, unsigned long __b) { return __b < __a ? __b : __a; }
1.88 +inline unsigned long (max) (unsigned long __a, unsigned long __b) { return __a < __b ? __b : __a; }
1.89 +# endif
1.90 +
1.91 +template <class _Tp, class _Compare>
1.92 +inline const _Tp& (min)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
1.93 + return __comp(__b, __a) ? __b : __a;
1.94 +}
1.95 +
1.96 +template <class _Tp, class _Compare>
1.97 +inline const _Tp& (max)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
1.98 + return __comp(__a, __b) ? __b : __a;
1.99 +}
1.100 +
1.101 +//--------------------------------------------------
1.102 +// copy
1.103 +
1.104 +// All of these auxiliary functions serve two purposes. (1) Replace
1.105 +// calls to copy with memmove whenever possible. (Memmove, not memcpy,
1.106 +// because the input and output ranges are permitted to overlap.)
1.107 +// (2) If we're using random access iterators, then write the loop as
1.108 +// a for loop with an explicit count.
1.109 +
1.110 +template <class _InputIter, class _OutputIter, class _Distance>
1.111 +inline _OutputIter __copy(_InputIter __first, _InputIter __last,
1.112 + _OutputIter __result,
1.113 + const input_iterator_tag &, _Distance*) {
1.114 + for ( ; __first != __last; ++__result, ++__first)
1.115 + *__result = *__first;
1.116 + return __result;
1.117 +}
1.118 +
1.119 +# if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
1.120 +template <class _InputIter, class _OutputIter, class _Distance>
1.121 +inline _OutputIter __copy(_InputIter __first, _InputIter __last,
1.122 + _OutputIter __result, const forward_iterator_tag &, _Distance* ) {
1.123 + for ( ; __first != __last; ++__result, ++__first)
1.124 + *__result = *__first;
1.125 + return __result;
1.126 +}
1.127 +
1.128 +
1.129 +template <class _InputIter, class _OutputIter, class _Distance>
1.130 +inline _OutputIter __copy(_InputIter __first, _InputIter __last,
1.131 + _OutputIter __result, const bidirectional_iterator_tag &, _Distance* __dis) {
1.132 + for ( ; __first != __last; ++__result, ++__first)
1.133 + *__result = *__first;
1.134 + return __result;
1.135 +}
1.136 +# endif
1.137 +
1.138 +template <class _RandomAccessIter, class _OutputIter, class _Distance>
1.139 +inline _OutputIter
1.140 +__copy(_RandomAccessIter __first, _RandomAccessIter __last,
1.141 + _OutputIter __result, const random_access_iterator_tag &, _Distance*) {
1.142 + for (_Distance __n = __last - __first; __n > 0; --__n) {
1.143 + *__result = *__first;
1.144 + ++__first;
1.145 + ++__result;
1.146 + }
1.147 + return __result;
1.148 +}
1.149 +
1.150 +inline void*
1.151 +__copy_trivial(const void* __first, const void* __last, void* __result) {
1.152 + return (__last == __first) ? __result :
1.153 + ((char*)memmove(__result, __first, ((const char*)__last - (const char*)__first))) +
1.154 + ((const char*)__last - (const char*)__first);
1.155 +}
1.156 +
1.157 +//--------------------------------------------------
1.158 +// copy_backward auxiliary functions
1.159 +
1.160 +template <class _BidirectionalIter1, class _BidirectionalIter2,
1.161 + class _Distance>
1.162 +inline _BidirectionalIter2 __copy_backward(_BidirectionalIter1 __first,
1.163 + _BidirectionalIter1 __last,
1.164 + _BidirectionalIter2 __result,
1.165 + const bidirectional_iterator_tag &,
1.166 + _Distance*)
1.167 +{
1.168 + while (__first != __last)
1.169 + *--__result = *--__last;
1.170 + return __result;
1.171 +}
1.172 +
1.173 +template <class _RandomAccessIter, class _BidirectionalIter, class _Distance>
1.174 +inline _BidirectionalIter __copy_backward(_RandomAccessIter __first,
1.175 + _RandomAccessIter __last,
1.176 + _BidirectionalIter __result,
1.177 + const random_access_iterator_tag &,
1.178 + _Distance*)
1.179 +{
1.180 + for (_Distance __n = __last - __first; __n > 0; --__n)
1.181 + *--__result = *--__last;
1.182 + return __result;
1.183 +}
1.184 +
1.185 +inline void*
1.186 +__copy_trivial_backward(const void* __first, const void* __last, void* __result) {
1.187 + const ptrdiff_t _Num = (const char*)__last - (const char*)__first;
1.188 + return (_Num > 0) ? memmove((char*)__result - _Num, __first, _Num) : __result ;
1.189 +}
1.190 +
1.191 +template <class _InputIter, class _OutputIter>
1.192 +inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
1.193 + return __copy(__first, __last, __result,
1.194 + _STLP_ITERATOR_CATEGORY(__first, _InputIter),
1.195 + _STLP_DISTANCE_TYPE(__first, _InputIter));
1.196 +}
1.197 +template <class _InputIter, class _OutputIter>
1.198 +inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
1.199 +// we know they all pointers, so this cast is OK
1.200 + // return (_OutputIter)__copy_trivial(&(*__first), &(*__last), &(*__result));
1.201 + return (_OutputIter)__copy_trivial(__first, __last, __result);
1.202 +}
1.203 +
1.204 +template <class _InputIter, class _OutputIter>
1.205 +inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
1.206 + return __copy_ptrs(__first, __last, __result,
1.207 + _IsOKToMemCpy(_STLP_VALUE_TYPE(__first, _InputIter),
1.208 + _STLP_VALUE_TYPE(__result, _OutputIter))._Ret());
1.209 +}
1.210 +
1.211 +template <class _InputIter, class _OutputIter>
1.212 +inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
1.213 + return __copy(__first, __last, __result,
1.214 + _STLP_ITERATOR_CATEGORY(__first, _InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
1.215 +}
1.216 +
1.217 +template <class _InputIter, class _OutputIter>
1.218 +inline _OutputIter copy(_InputIter __first, _InputIter __last, _OutputIter __result) {
1.219 + _STLP_DEBUG_CHECK(__check_range(__first, __last))
1.220 + return __copy_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter> :: _Ret());
1.221 +}
1.222 +
1.223 +template <class _InputIter, class _OutputIter>
1.224 +inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
1.225 + return __copy_backward(__first, __last, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
1.226 +}
1.227 +template <class _InputIter, class _OutputIter>
1.228 +inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
1.229 + return (_OutputIter)__copy_trivial_backward(__first, __last, __result);
1.230 +}
1.231 +
1.232 +template <class _InputIter, class _OutputIter>
1.233 +inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
1.234 + return __copy_backward(__first, __last, __result, _STLP_ITERATOR_CATEGORY(__first,_InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
1.235 +}
1.236 +
1.237 +template <class _InputIter, class _OutputIter>
1.238 +inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
1.239 + return __copy_backward_ptrs(__first, __last, __result,
1.240 + _IsOKToMemCpy(_STLP_VALUE_TYPE(__first, _InputIter),
1.241 + _STLP_VALUE_TYPE(__result, _OutputIter))._Ret());
1.242 +}
1.243 +
1.244 +template <class _InputIter, class _OutputIter>
1.245 +inline _OutputIter copy_backward(_InputIter __first, _InputIter __last, _OutputIter __result) {
1.246 + _STLP_DEBUG_CHECK(__check_range(__first, __last))
1.247 + return __copy_backward_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter> :: _Ret() );
1.248 +}
1.249 +
1.250 +#if ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined ( _STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS )
1.251 +#define _STLP_DECLARE_COPY_TRIVIAL(_Tp) \
1.252 +inline _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) \
1.253 +{ return (_Tp*)__copy_trivial(__first, __last, __result); } \
1.254 +inline _Tp* copy_backward(const _Tp* __first, const _Tp* __last, _Tp* __result) \
1.255 +{ return (_Tp*)__copy_trivial_backward(__first, __last, __result); }
1.256 +
1.257 +_STLP_DECLARE_COPY_TRIVIAL(char)
1.258 +# ifndef _STLP_NO_SIGNED_BUILTINS
1.259 +_STLP_DECLARE_COPY_TRIVIAL(signed char)
1.260 +# endif
1.261 +_STLP_DECLARE_COPY_TRIVIAL(unsigned char)
1.262 +_STLP_DECLARE_COPY_TRIVIAL(short)
1.263 +_STLP_DECLARE_COPY_TRIVIAL(unsigned short)
1.264 +_STLP_DECLARE_COPY_TRIVIAL(int)
1.265 +_STLP_DECLARE_COPY_TRIVIAL(unsigned int)
1.266 +_STLP_DECLARE_COPY_TRIVIAL(long)
1.267 +_STLP_DECLARE_COPY_TRIVIAL(unsigned long)
1.268 +#if !defined(_STLP_NO_WCHAR_T) && !defined (_STLP_WCHAR_T_IS_USHORT)
1.269 +_STLP_DECLARE_COPY_TRIVIAL(wchar_t)
1.270 +#endif
1.271 +#ifdef _STLP_LONG_LONG
1.272 +_STLP_DECLARE_COPY_TRIVIAL(long long)
1.273 +_STLP_DECLARE_COPY_TRIVIAL(unsigned long long)
1.274 +#endif
1.275 +_STLP_DECLARE_COPY_TRIVIAL(float)
1.276 +_STLP_DECLARE_COPY_TRIVIAL(double)
1.277 +# ifndef _STLP_NO_LONG_DOUBLE
1.278 +_STLP_DECLARE_COPY_TRIVIAL(long double)
1.279 +# endif
1.280 +#undef _STLP_DECLARE_COPY_TRIVIAL
1.281 +#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
1.282 +
1.283 +//--------------------------------------------------
1.284 +// copy_n (not part of the C++ standard)
1.285 +
1.286 +template <class _InputIter, class _Size, class _OutputIter>
1.287 +_STLP_INLINE_LOOP
1.288 +pair<_InputIter, _OutputIter> __copy_n(_InputIter __first, _Size __count,
1.289 + _OutputIter __result,
1.290 + const input_iterator_tag &) {
1.291 + for ( ; __count > 0; --__count) {
1.292 + *__result = *__first;
1.293 + ++__first;
1.294 + ++__result;
1.295 + }
1.296 + return pair<_InputIter, _OutputIter>(__first, __result);
1.297 +}
1.298 +
1.299 +template <class _RAIter, class _Size, class _OutputIter>
1.300 +inline pair<_RAIter, _OutputIter>
1.301 +__copy_n(_RAIter __first, _Size __count,
1.302 + _OutputIter __result,
1.303 + const random_access_iterator_tag &) {
1.304 + _RAIter __last = __first + __count;
1.305 + return pair<_RAIter, _OutputIter>(__last, copy(__first, __last, __result));
1.306 +}
1.307 +
1.308 +template <class _InputIter, class _Size, class _OutputIter>
1.309 +inline pair<_InputIter, _OutputIter>
1.310 +__copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
1.311 + _STLP_FIX_LITERAL_BUG(__first)
1.312 + return __copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
1.313 +}
1.314 +
1.315 +template <class _InputIter, class _Size, class _OutputIter>
1.316 +inline pair<_InputIter, _OutputIter>
1.317 +copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
1.318 + _STLP_FIX_LITERAL_BUG(__first)
1.319 + return __copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
1.320 +}
1.321 +
1.322 +//--------------------------------------------------
1.323 +// fill and fill_n
1.324 +
1.325 +
1.326 +template <class _ForwardIter, class _Tp>
1.327 +_STLP_INLINE_LOOP
1.328 +void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
1.329 + _STLP_DEBUG_CHECK(__check_range(__first, __last))
1.330 + for ( ; __first != __last; ++__first)
1.331 + *__first = __val;
1.332 +}
1.333 +
1.334 +template <class _OutputIter, class _Size, class _Tp>
1.335 +_STLP_INLINE_LOOP
1.336 +_OutputIter fill_n(_OutputIter __first, _Size __n, const _Tp& __val) {
1.337 + _STLP_FIX_LITERAL_BUG(__first)
1.338 + for ( ; __n > 0; --__n, ++__first)
1.339 + *__first = __val;
1.340 + return __first;
1.341 +}
1.342 +
1.343 +
1.344 +// Specialization: for one-byte types we can use memset.
1.345 +
1.346 +inline void fill(unsigned char* __first, unsigned char* __last,
1.347 + const unsigned char& __val) {
1.348 + unsigned char __tmp = __val;
1.349 + memset(__first, __tmp, __last - __first);
1.350 +}
1.351 +# ifndef _STLP_NO_SIGNED_BUILTINS
1.352 +inline void fill(signed char* __first, signed char* __last,
1.353 + const signed char& __val) {
1.354 + signed char __tmp = __val;
1.355 + memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
1.356 +}
1.357 +# endif
1.358 +inline void fill(char* __first, char* __last, const char& __val) {
1.359 + char __tmp = __val;
1.360 + memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
1.361 +}
1.362 +
1.363 +#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
1.364 +
1.365 +template <class _Size>
1.366 +inline unsigned char* fill_n(unsigned char* __first, _Size __n,
1.367 + const unsigned char& __val) {
1.368 + fill(__first, __first + __n, __val);
1.369 + return __first + __n;
1.370 +}
1.371 +
1.372 +template <class _Size>
1.373 +inline signed char* fill_n(char* __first, _Size __n,
1.374 + const signed char& __val) {
1.375 + fill(__first, __first + __n, __val);
1.376 + return __first + __n;
1.377 +}
1.378 +
1.379 +template <class _Size>
1.380 +inline char* fill_n(char* __first, _Size __n, const char& __val) {
1.381 + fill(__first, __first + __n, __val);
1.382 + return __first + __n;
1.383 +}
1.384 +
1.385 +#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
1.386 +
1.387 +
1.388 +//--------------------------------------------------
1.389 +// equal and mismatch
1.390 +
1.391 +template <class _InputIter1, class _InputIter2>
1.392 +_STLP_INLINE_LOOP
1.393 +pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
1.394 + _InputIter1 __last1,
1.395 + _InputIter2 __first2) {
1.396 + _STLP_FIX_LITERAL_BUG(__first2)
1.397 + _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.398 + while (__first1 != __last1 && *__first1 == *__first2) {
1.399 + ++__first1;
1.400 + ++__first2;
1.401 + }
1.402 + return pair<_InputIter1, _InputIter2>(__first1, __first2);
1.403 +}
1.404 +
1.405 +template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
1.406 +_STLP_INLINE_LOOP
1.407 +pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
1.408 + _InputIter1 __last1,
1.409 + _InputIter2 __first2,
1.410 + _BinaryPredicate __binary_pred) {
1.411 + _STLP_FIX_LITERAL_BUG(__first2)
1.412 + _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.413 + while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) {
1.414 + ++__first1;
1.415 + ++__first2;
1.416 + }
1.417 + return pair<_InputIter1, _InputIter2>(__first1, __first2);
1.418 +}
1.419 +
1.420 +template <class _InputIter1, class _InputIter2>
1.421 +_STLP_INLINE_LOOP
1.422 +bool equal(_InputIter1 __first1, _InputIter1 __last1,
1.423 + _InputIter2 __first2) {
1.424 + _STLP_FIX_LITERAL_BUG(__first1) _STLP_FIX_LITERAL_BUG(__last1) _STLP_FIX_LITERAL_BUG(__first2)
1.425 + _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.426 + for ( ; __first1 != __last1; ++__first1, ++__first2)
1.427 + if (!(*__first1 == *__first2))
1.428 + return false;
1.429 + return true;
1.430 +}
1.431 +
1.432 +template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
1.433 +_STLP_INLINE_LOOP
1.434 +bool equal(_InputIter1 __first1, _InputIter1 __last1,
1.435 + _InputIter2 __first2, _BinaryPredicate __binary_pred) {
1.436 + _STLP_FIX_LITERAL_BUG(__first2)
1.437 + _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.438 + for ( ; __first1 != __last1; ++__first1, ++__first2)
1.439 + if (!__binary_pred(*__first1, *__first2))
1.440 + return false;
1.441 + return true;
1.442 +}
1.443 +
1.444 +//--------------------------------------------------
1.445 +// lexicographical_compare and lexicographical_compare_3way.
1.446 +// (the latter is not part of the C++ standard.)
1.447 +
1.448 +template <class _InputIter1, class _InputIter2>
1.449 +bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
1.450 + _InputIter2 __first2, _InputIter2 __last2);
1.451 +
1.452 +template <class _InputIter1, class _InputIter2, class _Compare>
1.453 +bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
1.454 + _InputIter2 __first2, _InputIter2 __last2,
1.455 + _Compare __comp);
1.456 +
1.457 +inline bool
1.458 +lexicographical_compare(const unsigned char* __first1,
1.459 + const unsigned char* __last1,
1.460 + const unsigned char* __first2,
1.461 + const unsigned char* __last2)
1.462 +{
1.463 + const size_t __len1 = __last1 - __first1;
1.464 + const size_t __len2 = __last2 - __first2;
1.465 + _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.466 + _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
1.467 +
1.468 + const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
1.469 + return __result != 0 ? (__result < 0) : (__len1 < __len2);
1.470 +}
1.471 +
1.472 +
1.473 +# if !(CHAR_MAX == SCHAR_MAX)
1.474 +inline bool lexicographical_compare(const char* __first1, const char* __last1,
1.475 + const char* __first2, const char* __last2)
1.476 +{
1.477 + _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.478 + _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
1.479 +
1.480 + return lexicographical_compare((const unsigned char*) __first1,
1.481 + (const unsigned char*) __last1,
1.482 + (const unsigned char*) __first2,
1.483 + (const unsigned char*) __last2);
1.484 +}
1.485 +#endif /* CHAR_MAX == SCHAR_MAX */
1.486 +
1.487 +template <class _InputIter1, class _InputIter2>
1.488 +int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
1.489 + _InputIter2 __first2, _InputIter2 __last2);
1.490 +
1.491 +inline int
1.492 +__lexicographical_compare_3way(const unsigned char* __first1,
1.493 + const unsigned char* __last1,
1.494 + const unsigned char* __first2,
1.495 + const unsigned char* __last2)
1.496 +{
1.497 + const ptrdiff_t __len1 = __last1 - __first1;
1.498 + const ptrdiff_t __len2 = __last2 - __first2;
1.499 + const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
1.500 + return __result != 0 ? __result
1.501 + : (__len1 == __len2 ? 0 : (__len1 < __len2 ? -1 : 1));
1.502 +}
1.503 +
1.504 +
1.505 +# if !(CHAR_MAX == SCHAR_MAX)
1.506 +inline int
1.507 +__lexicographical_compare_3way(const char* __first1, const char* __last1,
1.508 + const char* __first2, const char* __last2)
1.509 +{
1.510 + return __lexicographical_compare_3way((const unsigned char*) __first1,
1.511 + (const unsigned char*) __last1,
1.512 + (const unsigned char*) __first2,
1.513 + (const unsigned char*) __last2);
1.514 +}
1.515 +# endif
1.516 +
1.517 +# ifndef _STLP_NO_EXTENSIONS
1.518 +
1.519 +template <class _InputIter1, class _InputIter2>
1.520 +int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
1.521 + _InputIter2 __first2, _InputIter2 __last2);
1.522 +
1.523 +# endif /* EXTENSIONS */
1.524 +
1.525 +// count
1.526 +template <class _InputIter, class _Tp>
1.527 +_STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
1.528 +count(_InputIter __first, _InputIter __last, const _Tp& __val) {
1.529 + _STLP_DEBUG_CHECK(__check_range(__first, __last))
1.530 + _STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
1.531 + for ( ; __first != __last; ++__first)
1.532 + if (*__first == __val)
1.533 + ++__n;
1.534 + return __n;
1.535 +}
1.536 +
1.537 +// find and find_if. Note find may be expressed in terms of find_if if appropriate binder was available.
1.538 +template <class _InputIter, class _Tp>
1.539 +_InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val);
1.540 +template <class _InputIter, class _Predicate>
1.541 +_InputIter find_if(_InputIter __first, _InputIter __last, _Predicate __pred);
1.542 +
1.543 +// search.
1.544 +template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
1.545 +_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
1.546 + _ForwardIter2 __first2, _ForwardIter2 __last2, _BinaryPred __predicate);
1.547 +
1.548 +// find_first_of
1.549 +template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
1.550 +_InputIter __find_first_of(_InputIter __first1, _InputIter __last1,
1.551 + _ForwardIter __first2, _ForwardIter __last2,
1.552 + _BinaryPredicate __comp);
1.553 +
1.554 +template <class _ForwardIter1, class _ForwardIter2,
1.555 + class _BinaryPredicate>
1.556 +_ForwardIter1
1.557 +find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
1.558 + _ForwardIter2 __first2, _ForwardIter2 __last2,
1.559 + _BinaryPredicate __comp);
1.560 +
1.561 +// replace
1.562 +template <class _ForwardIter, class _Tp>
1.563 +_STLP_INLINE_LOOP void
1.564 +replace(_ForwardIter __first, _ForwardIter __last,
1.565 + const _Tp& __old_value, const _Tp& __new_value) {
1.566 + _STLP_DEBUG_CHECK(__check_range(__first, __last))
1.567 + for ( ; __first != __last; ++__first)
1.568 + if (*__first == __old_value)
1.569 + *__first = __new_value;
1.570 +}
1.571 +
1.572 +template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
1.573 +_ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
1.574 + const _Tp& __val, _Compare __comp, _Distance*);
1.575 +
1.576 +_STLP_END_NAMESPACE
1.577 +
1.578 +# if !defined (_STLP_LINK_TIME_INSTANTIATION)
1.579 +# include <stl/_algobase.c>
1.580 +# endif
1.581 +
1.582 +#endif /* _STLP_INTERNAL_ALGOBASE_H */
1.583 +
1.584 +// Local Variables:
1.585 +// mode:C++
1.586 +// End:
1.587 +