1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_algobase.c Wed Mar 31 12:27:01 2010 +0100
1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_algobase.c Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -1,5 +1,7 @@
1.4 /*
1.5 *
1.6 + * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.7 + *
1.8 * Copyright (c) 1994
1.9 * Hewlett-Packard Company
1.10 *
1.11 @@ -9,13 +11,13 @@
1.12 * Copyright (c) 1997
1.13 * Moscow Center for SPARC Technology
1.14 *
1.15 - * Copyright (c) 1999
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 + * Permission to use or copy this software for any purpose is hereby granted
1.24 * without fee, provided the above notices are retained on all copies.
1.25 * Permission to modify the code and to distribute modified code is granted,
1.26 * provided the above notices are retained, and a notice that the code was
1.27 @@ -25,24 +27,25 @@
1.28 #ifndef _STLP_ALGOBASE_C
1.29 #define _STLP_ALGOBASE_C
1.30
1.31 -# if !defined (_STLP_INTERNAL_ALGOBASE_H)
1.32 +#ifndef _STLP_INTERNAL_ALGOBASE_H
1.33 # include <stl/_algobase.h>
1.34 -# endif
1.35 +#endif
1.36
1.37 _STLP_BEGIN_NAMESPACE
1.38
1.39 template <class _InputIter1, class _InputIter2>
1.40 bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
1.41 _InputIter2 __first2, _InputIter2 __last2) {
1.42 - _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.43 - _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
1.44 - for ( ; __first1 != __last1 && __first2 != __last2
1.45 - ; ++__first1, ++__first2) {
1.46 - if (*__first1 < *__first2)
1.47 - return true;
1.48 - if (*__first2 < *__first1)
1.49 - return false;
1.50 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
1.51 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
1.52 + for ( ; __first1 != __last1 && __first2 != __last2
1.53 + ; ++__first1, ++__first2) {
1.54 + if (*__first1 < *__first2) {
1.55 + return true;
1.56 }
1.57 + if (*__first2 < *__first1)
1.58 + return false;
1.59 + }
1.60 return __first1 == __last1 && __first2 != __last2;
1.61 }
1.62
1.63 @@ -50,27 +53,30 @@
1.64 bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
1.65 _InputIter2 __first2, _InputIter2 __last2,
1.66 _Compare __comp) {
1.67 - _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.68 - _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
1.69 - for ( ; __first1 != __last1 && __first2 != __last2
1.70 - ; ++__first1, ++__first2) {
1.71 - if (__comp(*__first1, *__first2))
1.72 - return true;
1.73 - if (__comp(*__first2, *__first1))
1.74 - return false;
1.75 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
1.76 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
1.77 + for ( ; __first1 != __last1 && __first2 != __last2
1.78 + ; ++__first1, ++__first2) {
1.79 + if (__comp(*__first1, *__first2)) {
1.80 + return true;
1.81 }
1.82 + if (__comp(*__first2, *__first1))
1.83 + return false;
1.84 + }
1.85 return __first1 == __last1 && __first2 != __last2;
1.86 }
1.87
1.88 -# ifndef _STLP_NO_EXTENSIONS
1.89 +#if !defined (_STLP_NO_EXTENSIONS)
1.90 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.91
1.92 template <class _InputIter1, class _InputIter2>
1.93 int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
1.94 - _InputIter2 __first2, _InputIter2 __last2)
1.95 -{
1.96 + _InputIter2 __first2, _InputIter2 __last2) {
1.97 while (__first1 != __last1 && __first2 != __last2) {
1.98 - if (*__first1 < *__first2)
1.99 + if (*__first1 < *__first2) {
1.100 + _STLP_VERBOSE_ASSERT(!(*__first2 < *__first1), _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
1.101 return -1;
1.102 + }
1.103 if (*__first2 < *__first1)
1.104 return 1;
1.105 ++__first1;
1.106 @@ -84,22 +90,23 @@
1.107 }
1.108 }
1.109
1.110 +_STLP_MOVE_TO_STD_NAMESPACE
1.111
1.112 template <class _InputIter1, class _InputIter2>
1.113 int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
1.114 - _InputIter2 __first2, _InputIter2 __last2)
1.115 -{
1.116 - _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.117 - _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
1.118 - return __lexicographical_compare_3way(__first1, __last1, __first2, __last2);
1.119 + _InputIter2 __first2, _InputIter2 __last2) {
1.120 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
1.121 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
1.122 + return _STLP_PRIV __lexicographical_compare_3way(__first1, __last1, __first2, __last2);
1.123 }
1.124 -# endif
1.125 +#endif
1.126 +
1.127 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.128
1.129 template <class _RandomAccessIter, class _Tp>
1.130 _STLP_INLINE_LOOP _RandomAccessIter __find(_RandomAccessIter __first, _RandomAccessIter __last,
1.131 const _Tp& __val,
1.132 - const random_access_iterator_tag &)
1.133 -{
1.134 + const random_access_iterator_tag &) {
1.135 _STLP_DIFFERENCE_TYPE(_RandomAccessIter) __trip_count = (__last - __first) >> 2;
1.136
1.137 for ( ; __trip_count > 0 ; --__trip_count) {
1.138 @@ -116,7 +123,7 @@
1.139 ++__first;
1.140 }
1.141
1.142 - switch(__last - __first) {
1.143 + switch (__last - __first) {
1.144 case 3:
1.145 if (*__first == __val) return __first;
1.146 ++__first;
1.147 @@ -125,18 +132,28 @@
1.148 ++__first;
1.149 case 1:
1.150 if (*__first == __val) return __first;
1.151 - ++__first;
1.152 + //++__first;
1.153 case 0:
1.154 default:
1.155 return __last;
1.156 }
1.157 }
1.158
1.159 +inline char*
1.160 +__find(char* __first, char* __last, char __val, const random_access_iterator_tag &) {
1.161 + void *res = memchr(__first, __val, __last - __first);
1.162 + return res != 0 ? __STATIC_CAST(char*, res) : __last;
1.163 +}
1.164 +inline const char*
1.165 +__find(const char* __first, const char* __last, char __val, const random_access_iterator_tag &) {
1.166 + const void *res = memchr(__first, __val, __last - __first);
1.167 + return res != 0 ? __STATIC_CAST(const char*, res) : __last;
1.168 +}
1.169 +
1.170 template <class _RandomAccessIter, class _Predicate>
1.171 _STLP_INLINE_LOOP _RandomAccessIter __find_if(_RandomAccessIter __first, _RandomAccessIter __last,
1.172 _Predicate __pred,
1.173 - const random_access_iterator_tag &)
1.174 -{
1.175 + const random_access_iterator_tag &) {
1.176 _STLP_DIFFERENCE_TYPE(_RandomAccessIter) __trip_count = (__last - __first) >> 2;
1.177
1.178 for ( ; __trip_count > 0 ; --__trip_count) {
1.179 @@ -162,7 +179,7 @@
1.180 ++__first;
1.181 case 1:
1.182 if (__pred(*__first)) return __first;
1.183 - // ++__first;
1.184 + //++__first;
1.185 case 0:
1.186 default:
1.187 return __last;
1.188 @@ -170,83 +187,71 @@
1.189 }
1.190
1.191 template <class _InputIter, class _Tp>
1.192 -inline _InputIter __find(_InputIter __first, _InputIter __last,
1.193 - const _Tp& __val,
1.194 - const input_iterator_tag &)
1.195 -{
1.196 - while (__first != __last && !(*__first == __val))
1.197 - ++__first;
1.198 +_STLP_INLINE_LOOP _InputIter __find(_InputIter __first, _InputIter __last,
1.199 + const _Tp& __val,
1.200 + const input_iterator_tag &) {
1.201 + while (__first != __last && !(*__first == __val)) ++__first;
1.202 return __first;
1.203 }
1.204
1.205 template <class _InputIter, class _Predicate>
1.206 -inline _InputIter __find_if(_InputIter __first, _STLP_MPW_EXTRA_CONST _InputIter __last,
1.207 - _Predicate __pred,
1.208 - const input_iterator_tag &)
1.209 -{
1.210 +_STLP_INLINE_LOOP _InputIter __find_if(_InputIter __first, _STLP_MPW_EXTRA_CONST _InputIter __last,
1.211 + _Predicate __pred,
1.212 + const input_iterator_tag &) {
1.213 while (__first != __last && !__pred(*__first))
1.214 ++__first;
1.215 return __first;
1.216 }
1.217
1.218 +_STLP_MOVE_TO_STD_NAMESPACE
1.219 +
1.220 template <class _InputIter, class _Predicate>
1.221 _InputIter find_if(_InputIter __first, _InputIter __last,
1.222 _Predicate __pred) {
1.223 - _STLP_DEBUG_CHECK(__check_range(__first, __last))
1.224 - return __find_if(__first, __last, __pred, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
1.225 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
1.226 + return _STLP_PRIV __find_if(__first, __last, __pred, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
1.227 }
1.228
1.229 template <class _InputIter, class _Tp>
1.230 -_InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val)
1.231 -{
1.232 - _STLP_DEBUG_CHECK(__check_range(__first, __last))
1.233 - return __find(__first, __last, __val, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
1.234 +_InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val) {
1.235 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
1.236 + return _STLP_PRIV __find(__first, __last, __val, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
1.237 }
1.238
1.239 template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
1.240 _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
1.241 _ForwardIter2 __first2, _ForwardIter2 __last2,
1.242 - _BinaryPred __predicate)
1.243 -{
1.244 - _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.245 - _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
1.246 - // Test for empty ranges
1.247 - if (__first1 == __last1 || __first2 == __last2)
1.248 - return __first1;
1.249 + _BinaryPred __pred) {
1.250 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
1.251 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
1.252 + // Test for empty ranges
1.253 + if (__first1 == __last1 || __first2 == __last2)
1.254 + return __first1;
1.255
1.256 // Test for a pattern of length 1.
1.257 - _ForwardIter2 __tmp(__first2);
1.258 - ++__tmp;
1.259 - if (__tmp == __last2) {
1.260 - while (__first1 != __last1 && !__predicate(*__first1, *__first2))
1.261 + _ForwardIter2 __p1(__first2);
1.262 +
1.263 + if ( ++__p1 == __last2 ) {
1.264 + while (__first1 != __last1 && !__pred(*__first1, *__first2)) {
1.265 ++__first1;
1.266 - return __first1;
1.267 + }
1.268 + return __first1;
1.269 }
1.270 -
1.271 +
1.272 // General case.
1.273
1.274 - _ForwardIter2 __p1, __p;
1.275 -
1.276 - __p1 = __first2; ++__p1;
1.277 -
1.278 - // _ForwardIter1 __current = __first1;
1.279 -
1.280 - while (__first1 != __last1) {
1.281 - while (__first1 != __last1) {
1.282 - if (__predicate(*__first1, *__first2))
1.283 - break;
1.284 + for ( ; ; ) { // __first1 != __last1 will be checked below
1.285 + while (__first1 != __last1 && !__pred(*__first1, *__first2)) {
1.286 ++__first1;
1.287 }
1.288 - while (__first1 != __last1 && !__predicate(*__first1, *__first2))
1.289 - ++__first1;
1.290 - if (__first1 == __last1)
1.291 + if (__first1 == __last1) {
1.292 return __last1;
1.293 -
1.294 - __p = __p1;
1.295 - _ForwardIter1 __current = __first1;
1.296 + }
1.297 + _ForwardIter2 __p = __p1;
1.298 + _ForwardIter1 __current = __first1;
1.299 if (++__current == __last1) return __last1;
1.300
1.301 - while (__predicate(*__current, *__p)) {
1.302 + while (__pred(*__current, *__p)) {
1.303 if (++__p == __last2)
1.304 return __first1;
1.305 if (++__current == __last1)
1.306 @@ -258,41 +263,41 @@
1.307 return __first1;
1.308 }
1.309
1.310 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.311 +
1.312 // find_first_of, with and without an explicitly supplied comparison function.
1.313 -
1.314 template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
1.315 _InputIter __find_first_of(_InputIter __first1, _InputIter __last1,
1.316 _ForwardIter __first2, _ForwardIter __last2,
1.317 _BinaryPredicate __comp) {
1.318 - for ( ; __first1 != __last1; ++__first1)
1.319 - for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter)
1.320 - if (__comp(*__first1, *__iter))
1.321 + for ( ; __first1 != __last1; ++__first1) {
1.322 + for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter) {
1.323 + if (__comp(*__first1, *__iter)) {
1.324 return __first1;
1.325 + }
1.326 + }
1.327 + }
1.328 return __last1;
1.329 }
1.330
1.331 -
1.332 // find_end, with and without an explicitly supplied comparison function.
1.333 // Search [first2, last2) as a subsequence in [first1, last1), and return
1.334 // the *last* possible match. Note that find_end for bidirectional iterators
1.335 // is much faster than for forward iterators.
1.336
1.337 -// find_end for forward iterators.
1.338 -
1.339 +// find_end for forward iterators.
1.340 template <class _ForwardIter1, class _ForwardIter2,
1.341 class _BinaryPredicate>
1.342 _ForwardIter1 __find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
1.343 _ForwardIter2 __first2, _ForwardIter2 __last2,
1.344 const forward_iterator_tag &, const forward_iterator_tag &,
1.345 - _BinaryPredicate __comp)
1.346 -{
1.347 + _BinaryPredicate __comp) {
1.348 if (__first2 == __last2)
1.349 return __last1;
1.350 else {
1.351 _ForwardIter1 __result = __last1;
1.352 - while (1) {
1.353 - _ForwardIter1 __new_result
1.354 - = search(__first1, __last1, __first2, __last2, __comp);
1.355 + for (;;) {
1.356 + _ForwardIter1 __new_result = search(__first1, __last1, __first2, __last2, __comp);
1.357 if (__new_result == __last1)
1.358 return __result;
1.359 else {
1.360 @@ -304,23 +309,26 @@
1.361 }
1.362 }
1.363
1.364 +_STLP_MOVE_TO_STD_NAMESPACE
1.365 +
1.366 // find_end for bidirectional iterators. Requires partial specialization.
1.367 -#if defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
1.368 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
1.369
1.370 -#if ! defined (_STLP_INTERNAL_ITERATOR_H)
1.371 +# ifndef _STLP_INTERNAL_ITERATOR_H
1.372 _STLP_END_NAMESPACE
1.373 -# include <stl/_iterator.h>
1.374 -_STLP_BEGIN_NAMESPACE
1.375 -#endif
1.376 +# include <stl/_iterator.h>
1.377 +_STLP_BEGIN_NAMESPACE
1.378 +# endif /*_STLP_INTERNAL_ITERATOR_H*/
1.379 +
1.380 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.381
1.382 template <class _BidirectionalIter1, class _BidirectionalIter2,
1.383 - class _BinaryPredicate>
1.384 + class _BinaryPredicate>
1.385 _BidirectionalIter1
1.386 __find_end(_BidirectionalIter1 __first1, _BidirectionalIter1 __last1,
1.387 _BidirectionalIter2 __first2, _BidirectionalIter2 __last2,
1.388 - const bidirectional_iterator_tag &, const bidirectional_iterator_tag &,
1.389 - _BinaryPredicate __comp)
1.390 -{
1.391 + const bidirectional_iterator_tag &, const bidirectional_iterator_tag &,
1.392 + _BinaryPredicate __comp) {
1.393 typedef reverse_iterator<_BidirectionalIter1> _RevIter1;
1.394 typedef reverse_iterator<_BidirectionalIter2> _RevIter2;
1.395
1.396 @@ -338,32 +346,34 @@
1.397 return __result;
1.398 }
1.399 }
1.400 +
1.401 +_STLP_MOVE_TO_STD_NAMESPACE
1.402 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
1.403
1.404 -template <class _ForwardIter1, class _ForwardIter2,
1.405 - class _BinaryPredicate>
1.406 -_ForwardIter1
1.407 -find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
1.408 +template <class _ForwardIter1, class _ForwardIter2,
1.409 + class _BinaryPredicate>
1.410 +_ForwardIter1
1.411 +find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
1.412 _ForwardIter2 __first2, _ForwardIter2 __last2,
1.413 - _BinaryPredicate __comp)
1.414 -{
1.415 - _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
1.416 - _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
1.417 - return __find_end(__first1, __last1, __first2, __last2,
1.418 -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
1.419 - _STLP_ITERATOR_CATEGORY(__first1, _ForwardIter1),
1.420 - _STLP_ITERATOR_CATEGORY(__first2, _ForwardIter2),
1.421 -# else
1.422 - forward_iterator_tag(),
1.423 - forward_iterator_tag(),
1.424 -# endif
1.425 - __comp);
1.426 + _BinaryPredicate __comp) {
1.427 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
1.428 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
1.429 + return _STLP_PRIV __find_end(__first1, __last1, __first2, __last2,
1.430 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
1.431 + _STLP_ITERATOR_CATEGORY(__first1, _ForwardIter1),
1.432 + _STLP_ITERATOR_CATEGORY(__first2, _ForwardIter2),
1.433 +#else
1.434 + forward_iterator_tag(),
1.435 + forward_iterator_tag(),
1.436 +#endif
1.437 + __comp);
1.438 }
1.439
1.440 -template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
1.441 -_ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
1.442 - const _Tp& __val, _Compare __comp, _Distance*)
1.443 -{
1.444 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.445 +
1.446 +template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
1.447 +_ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
1.448 + _Compare1 __comp1, _Compare2 __comp2, _Distance*) {
1.449 _Distance __len = distance(__first, __last);
1.450 _Distance __half;
1.451 _ForwardIter __middle;
1.452 @@ -372,7 +382,8 @@
1.453 __half = __len >> 1;
1.454 __middle = __first;
1.455 advance(__middle, __half);
1.456 - if (__comp(*__middle, __val)) {
1.457 + if (__comp1(*__middle, __val)) {
1.458 + _STLP_VERBOSE_ASSERT(!__comp2(__val, *__middle), _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
1.459 __first = __middle;
1.460 ++__first;
1.461 __len = __len - __half - 1;
1.462 @@ -380,9 +391,12 @@
1.463 else
1.464 __len = __half;
1.465 }
1.466 + if (&__comp2) {/* do nothing. to avoid warnings */}
1.467 return __first;
1.468 }
1.469
1.470 +_STLP_MOVE_TO_STD_NAMESPACE
1.471 +
1.472 _STLP_END_NAMESPACE
1.473
1.474 #endif /* _STLP_ALGOBASE_C */