/home/ntakagi/work/STLport-5.1.5/stlport/stl/_algo.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_ALGO_H
00031 #define _STLP_INTERNAL_ALGO_H
00032 
00033 #ifndef _STLP_INTERNAL_ALGOBASE_H
00034 #  include <stl/_algobase.h>
00035 #endif
00036 
00037 #ifndef _STLP_INTERNAL_HEAP_H
00038 #  include <stl/_heap.h>
00039 #endif
00040 
00041 #ifndef _STLP_INTERNAL_ITERATOR_H
00042 #  include <stl/_iterator.h>
00043 #endif
00044 
00045 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
00046 #  include <stl/_function_base.h>
00047 #endif
00048 
00049 #if defined (__SUNPRO_CC) && !defined (_STLP_INTERNAL_CSTDIO)
00050 // remove() conflict
00051 #  include <stl/_cstdio.h>
00052 #endif
00053 
00054 _STLP_BEGIN_NAMESPACE
00055 
00056 // for_each.  Apply a function to every element of a range.
00057 template <class _InputIter, class _Function>
00058 _STLP_INLINE_LOOP _Function
00059 for_each(_InputIter __first, _InputIter __last, _Function __f) {
00060   for ( ; __first != __last; ++__first)
00061     __f(*__first);
00062   return __f;
00063 }
00064 
00065 // count_if
00066 template <class _InputIter, class _Predicate>
00067 _STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
00068 count_if(_InputIter __first, _InputIter __last, _Predicate __pred) {
00069   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00070   _STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
00071   for ( ; __first != __last; ++__first) {
00072     if (__pred(*__first))
00073       ++__n;
00074   }
00075   return __n;
00076 }
00077 
00078 // adjacent_find.
00079 
00080 template <class _ForwardIter, class _BinaryPredicate>
00081 _STLP_INLINE_LOOP _ForwardIter
00082 adjacent_find(_ForwardIter __first, _ForwardIter __last,
00083               _BinaryPredicate __binary_pred) {
00084   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00085   if (__first == __last)
00086     return __last;
00087   _ForwardIter __next = __first;
00088   while(++__next != __last) {
00089     if (__binary_pred(*__first, *__next))
00090       return __first;
00091     __first = __next;
00092   }
00093   return __last;
00094 }
00095 
00096 template <class _ForwardIter>
00097 _STLP_INLINE_LOOP _ForwardIter
00098 adjacent_find(_ForwardIter __first, _ForwardIter __last) {
00099   return adjacent_find(__first, __last,
00100                        _STLP_PRIV __equal_to(_STLP_VALUE_TYPE(__first, _ForwardIter)));
00101 }
00102 
00103 #if !defined (_STLP_NO_ANACHRONISMS)
00104 template <class _InputIter, class _Tp, class _Size>
00105 _STLP_INLINE_LOOP void
00106 count(_InputIter __first, _InputIter __last, const _Tp& __val, _Size& __n) {
00107   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00108     for ( ; __first != __last; ++__first)
00109       if (*__first == __val)
00110         ++__n;
00111 }
00112 
00113 template <class _InputIter, class _Predicate, class _Size>
00114 _STLP_INLINE_LOOP void
00115 count_if(_InputIter __first, _InputIter __last, _Predicate __pred, _Size& __n) {
00116   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00117   for ( ; __first != __last; ++__first)
00118     if (__pred(*__first))
00119       ++__n;
00120 }
00121 #endif
00122 
00123 template <class _ForwardIter1, class _ForwardIter2>
00124 _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
00125                      _ForwardIter2 __first2, _ForwardIter2 __last2);
00126 
00127 // search_n.  Search for __count consecutive copies of __val.
00128 template <class _ForwardIter, class _Integer, class _Tp>
00129 _ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
00130                       _Integer __count, const _Tp& __val);
00131 template <class _ForwardIter, class _Integer, class _Tp, class _BinaryPred>
00132 _ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
00133                       _Integer __count, const _Tp& __val, _BinaryPred __binary_pred);
00134 
00135 template <class _InputIter, class _ForwardIter>
00136 inline _InputIter find_first_of(_InputIter __first1, _InputIter __last1,
00137                                 _ForwardIter __first2, _ForwardIter __last2) {
00138   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
00139   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
00140   return _STLP_PRIV __find_first_of(__first1, __last1, __first2, __last2,
00141                                     _STLP_PRIV __equal_to(_STLP_VALUE_TYPE(__first1, _InputIter)));
00142 }
00143 
00144 template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
00145 inline _InputIter
00146 find_first_of(_InputIter __first1, _InputIter __last1,
00147               _ForwardIter __first2, _ForwardIter __last2, _BinaryPredicate __comp) {
00148   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
00149   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
00150   return _STLP_PRIV __find_first_of(__first1, __last1, __first2, __last2, __comp);
00151 }
00152 
00153 template <class _ForwardIter1, class _ForwardIter2>
00154 _ForwardIter1
00155 find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
00156          _ForwardIter2 __first2, _ForwardIter2 __last2);
00157 
00158 // swap_ranges
00159 template <class _ForwardIter1, class _ForwardIter2>
00160 _STLP_INLINE_LOOP _ForwardIter2
00161 swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 __first2) {
00162   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
00163   for ( ; __first1 != __last1; ++__first1, ++__first2)
00164     iter_swap(__first1, __first2);
00165   return __first2;
00166 }
00167 
00168 // transform
00169 template <class _InputIter, class _OutputIter, class _UnaryOperation>
00170 _STLP_INLINE_LOOP _OutputIter
00171 transform(_InputIter __first, _InputIter __last, _OutputIter __result, _UnaryOperation __opr) {
00172   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00173   for ( ; __first != __last; ++__first, ++__result)
00174     *__result = __opr(*__first);
00175   return __result;
00176 }
00177 template <class _InputIter1, class _InputIter2, class _OutputIter, class _BinaryOperation>
00178 _STLP_INLINE_LOOP _OutputIter
00179 transform(_InputIter1 __first1, _InputIter1 __last1,
00180           _InputIter2 __first2, _OutputIter __result,_BinaryOperation __binary_op) {
00181   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
00182   for ( ; __first1 != __last1; ++__first1, ++__first2, ++__result)
00183     *__result = __binary_op(*__first1, *__first2);
00184   return __result;
00185 }
00186 
00187 // replace_if, replace_copy, replace_copy_if
00188 
00189 template <class _ForwardIter, class _Predicate, class _Tp>
00190 _STLP_INLINE_LOOP void
00191 replace_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred, const _Tp& __new_value) {
00192   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00193   for ( ; __first != __last; ++__first)
00194     if (__pred(*__first))
00195       *__first = __new_value;
00196 }
00197 
00198 template <class _InputIter, class _OutputIter, class _Tp>
00199 _STLP_INLINE_LOOP  _OutputIter
00200 replace_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
00201              const _Tp& __old_value, const _Tp& __new_value) {
00202   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00203   for ( ; __first != __last; ++__first, ++__result)
00204     *__result = *__first == __old_value ? __new_value : *__first;
00205   return __result;
00206 }
00207 
00208 template <class _Iterator, class _OutputIter, class _Predicate, class _Tp>
00209 _STLP_INLINE_LOOP _OutputIter
00210 replace_copy_if(_Iterator __first, _Iterator __last,
00211                 _OutputIter __result,
00212                 _Predicate __pred, const _Tp& __new_value) {
00213   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00214   for ( ; __first != __last; ++__first, ++__result)
00215     *__result = __pred(*__first) ? __new_value : *__first;
00216   return __result;
00217 }
00218 
00219 // generate and generate_n
00220 
00221 template <class _ForwardIter, class _Generator>
00222 _STLP_INLINE_LOOP void
00223 generate(_ForwardIter __first, _ForwardIter __last, _Generator __gen) {
00224   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00225   for ( ; __first != __last; ++__first)
00226     *__first = __gen();
00227 }
00228 
00229 template <class _OutputIter, class _Size, class _Generator>
00230 _STLP_INLINE_LOOP void
00231 generate_n(_OutputIter __first, _Size __n, _Generator __gen) {
00232   for ( ; __n > 0; --__n, ++__first)
00233     *__first = __gen();
00234 }
00235 
00236 // remove, remove_if, remove_copy, remove_copy_if
00237 
00238 template <class _InputIter, class _OutputIter, class _Tp>
00239 _STLP_INLINE_LOOP _OutputIter
00240 remove_copy(_InputIter __first, _InputIter __last,_OutputIter __result, const _Tp& __val) {
00241   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00242   for ( ; __first != __last; ++__first) {
00243     if (!(*__first == __val)) {
00244       *__result = *__first;
00245       ++__result;
00246     }
00247   }
00248   return __result;
00249 }
00250 
00251 template <class _InputIter, class _OutputIter, class _Predicate>
00252 _STLP_INLINE_LOOP _OutputIter
00253 remove_copy_if(_InputIter __first, _InputIter __last, _OutputIter __result, _Predicate __pred) {
00254   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00255   for ( ; __first != __last; ++__first) {
00256     if (!__pred(*__first)) {
00257       *__result = *__first;
00258       ++__result;
00259     }
00260   }
00261   return __result;
00262 }
00263 
00264 template <class _ForwardIter, class _Tp>
00265 _STLP_INLINE_LOOP _ForwardIter
00266 remove(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
00267   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00268   __first = find(__first, __last, __val);
00269   if (__first == __last)
00270     return __first;
00271   else {
00272     _ForwardIter __next = __first;
00273     return remove_copy(++__next, __last, __first, __val);
00274   }
00275 }
00276 
00277 template <class _ForwardIter, class _Predicate>
00278 _STLP_INLINE_LOOP _ForwardIter
00279 remove_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred) {
00280   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00281   __first = find_if(__first, __last, __pred);
00282   if ( __first == __last )
00283     return __first;
00284   else {
00285     _ForwardIter __next = __first;
00286     return remove_copy_if(++__next, __last, __first, __pred);
00287   }
00288 }
00289 
00290 // unique and unique_copy
00291 template <class _InputIter, class _OutputIter>
00292 _OutputIter unique_copy(_InputIter __first, _InputIter __last, _OutputIter __result);
00293 
00294 template <class _InputIter, class _OutputIter, class _BinaryPredicate>
00295 _OutputIter unique_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
00296                         _BinaryPredicate __binary_pred);
00297 
00298 template <class _ForwardIter>
00299 inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last) {
00300   __first = adjacent_find(__first, __last);
00301   return unique_copy(__first, __last, __first);
00302 }
00303 
00304 template <class _ForwardIter, class _BinaryPredicate>
00305 inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last,
00306                            _BinaryPredicate __binary_pred) {
00307   __first = adjacent_find(__first, __last, __binary_pred);
00308   return unique_copy(__first, __last, __first, __binary_pred);
00309 }
00310 
00311 // reverse and reverse_copy, and their auxiliary functions
00312 
00313 template <class _BidirectionalIter>
00314 _STLP_INLINE_LOOP void
00315 __reverse(_BidirectionalIter __first, _BidirectionalIter __last, const bidirectional_iterator_tag &) {
00316   for (; __first != __last && __first != --__last; ++__first)
00317     iter_swap(__first,__last);
00318 }
00319 
00320 
00321 template <class _RandomAccessIter>
00322 _STLP_INLINE_LOOP void
00323 __reverse(_RandomAccessIter __first, _RandomAccessIter __last, const random_access_iterator_tag &) {
00324   for (; __first < __last; ++__first)
00325     iter_swap(__first, --__last);
00326 }
00327 
00328 template <class _BidirectionalIter>
00329 inline void
00330 reverse(_BidirectionalIter __first, _BidirectionalIter __last) {
00331   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00332   __reverse(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _BidirectionalIter));
00333 }
00334 
00335 template <class _BidirectionalIter, class _OutputIter>
00336 _STLP_INLINE_LOOP
00337 _OutputIter reverse_copy(_BidirectionalIter __first,
00338                          _BidirectionalIter __last,
00339                          _OutputIter __result) {
00340   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00341   while (__first != __last) {
00342     --__last;
00343     *__result = *__last;
00344     ++__result;
00345   }
00346   return __result;
00347 }
00348 
00349 _STLP_MOVE_TO_PRIV_NAMESPACE
00350 
00351 // rotate and rotate_copy, and their auxiliary functions
00352 template <class _EuclideanRingElement>
00353 _STLP_INLINE_LOOP
00354 _EuclideanRingElement __gcd(_EuclideanRingElement __m,
00355                             _EuclideanRingElement __n) {
00356   while (__n != 0) {
00357     _EuclideanRingElement __t = __m % __n;
00358     __m = __n;
00359     __n = __t;
00360   }
00361   return __m;
00362 }
00363 
00364 _STLP_MOVE_TO_STD_NAMESPACE
00365 
00366 template <class _ForwardIter>
00367 void rotate(_ForwardIter __first, _ForwardIter __middle, _ForwardIter __last);
00368 
00369 template <class _ForwardIter, class _OutputIter>
00370 inline _OutputIter rotate_copy(_ForwardIter __first, _ForwardIter __middle,
00371                                _ForwardIter __last, _OutputIter __result) {
00372   return copy(__first, __middle, copy(__middle, __last, __result));
00373 }
00374 
00375 // random_shuffle
00376 
00377 template <class _RandomAccessIter>
00378 void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last);
00379 
00380 template <class _RandomAccessIter, class _RandomNumberGenerator>
00381 void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last,
00382                     _RandomNumberGenerator& __rand);
00383 
00384 #if !defined (_STLP_NO_EXTENSIONS)
00385 // random_sample and random_sample_n (extensions, not part of the standard).
00386 
00387 template <class _ForwardIter, class _OutputIter, class _Distance>
00388 _OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
00389                             _OutputIter __out_ite, const _Distance __n);
00390 
00391 template <class _ForwardIter, class _OutputIter, class _Distance,
00392           class _RandomNumberGenerator>
00393 _OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
00394                             _OutputIter __out_ite, const _Distance __n,
00395                             _RandomNumberGenerator& __rand);
00396 
00397 template <class _InputIter, class _RandomAccessIter>
00398 _RandomAccessIter
00399 random_sample(_InputIter __first, _InputIter __last,
00400               _RandomAccessIter __out_first, _RandomAccessIter __out_last);
00401 
00402 template <class _InputIter, class _RandomAccessIter,
00403           class _RandomNumberGenerator>
00404 _RandomAccessIter
00405 random_sample(_InputIter __first, _InputIter __last,
00406               _RandomAccessIter __out_first, _RandomAccessIter __out_last,
00407               _RandomNumberGenerator& __rand);
00408 
00409 #endif /* _STLP_NO_EXTENSIONS */
00410 
00411 // partition, stable_partition, and their auxiliary functions
00412 
00413 template <class _ForwardIter, class _Predicate>
00414 _ForwardIter partition(_ForwardIter __first, _ForwardIter __last, _Predicate   __pred);
00415 
00416 template <class _ForwardIter, class _Predicate>
00417 _ForwardIter
00418 stable_partition(_ForwardIter __first, _ForwardIter __last, _Predicate __pred);
00419 
00420 // sort() and its auxiliary functions.
00421 _STLP_MOVE_TO_PRIV_NAMESPACE
00422 
00423 template <class _Size>
00424 inline _Size __lg(_Size __n) {
00425   _Size __k;
00426   for (__k = 0; __n != 1; __n >>= 1) ++__k;
00427   return __k;
00428 }
00429 
00430 _STLP_MOVE_TO_STD_NAMESPACE
00431 
00432 template <class _RandomAccessIter>
00433 void sort(_RandomAccessIter __first, _RandomAccessIter __last);
00434 template <class _RandomAccessIter, class _Compare>
00435 void sort(_RandomAccessIter __first, _RandomAccessIter __last, _Compare __comp);
00436 
00437 // stable_sort() and its auxiliary functions.
00438 template <class _RandomAccessIter>
00439 void stable_sort(_RandomAccessIter __first,
00440                  _RandomAccessIter __last);
00441 
00442 template <class _RandomAccessIter, class _Compare>
00443 void stable_sort(_RandomAccessIter __first,
00444                  _RandomAccessIter __last, _Compare __comp);
00445 
00446 // partial_sort, partial_sort_copy, and auxiliary functions.
00447 
00448 template <class _RandomAccessIter>
00449 void partial_sort(_RandomAccessIter __first, _RandomAccessIter __middle,
00450                   _RandomAccessIter __last);
00451 
00452 template <class _RandomAccessIter, class _Compare>
00453 void partial_sort(_RandomAccessIter __first,_RandomAccessIter __middle,
00454                   _RandomAccessIter __last, _Compare __comp);
00455 
00456 template <class _InputIter, class _RandomAccessIter>
00457 _RandomAccessIter
00458 partial_sort_copy(_InputIter __first, _InputIter __last,
00459                   _RandomAccessIter __result_first, _RandomAccessIter __result_last);
00460 
00461 template <class _InputIter, class _RandomAccessIter, class _Compare>
00462 _RandomAccessIter
00463 partial_sort_copy(_InputIter __first, _InputIter __last,
00464                   _RandomAccessIter __result_first,
00465                   _RandomAccessIter __result_last, _Compare __comp);
00466 
00467 // nth_element() and its auxiliary functions.
00468 template <class _RandomAccessIter>
00469 void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
00470                  _RandomAccessIter __last);
00471 
00472 template <class _RandomAccessIter, class _Compare>
00473 void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
00474                  _RandomAccessIter __last, _Compare __comp);
00475 
00476 // auxiliary class for lower_bound, etc.
00477 _STLP_MOVE_TO_PRIV_NAMESPACE
00478 
00479 template <class _T1, class _T2>
00480 struct __less_2 {
00481   bool operator() (const _T1& __x, const _T2& __y) const { return __x < __y ; }
00482 };
00483 
00484 template <class _T1, class _T2>
00485 __less_2<_T1,_T2> __less2(_T1*, _T2* ) { return __less_2<_T1, _T2>(); }
00486 
00487 #if defined (_STLP_FUNCTION_PARTIAL_ORDER)
00488 template <class _Tp>
00489 less<_Tp> __less2(_Tp*, _Tp* ) { return less<_Tp>(); }
00490 #endif
00491 
00492 _STLP_MOVE_TO_STD_NAMESPACE
00493 
00494 // Binary search (lower_bound, upper_bound, equal_range, binary_search).
00495 template <class _ForwardIter, class _Tp>
00496 inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
00497                                    const _Tp& __val) {
00498   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00499   return _STLP_PRIV __lower_bound(__first, __last, __val,
00500                                   _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
00501                                   _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
00502                                   _STLP_DISTANCE_TYPE(__first, _ForwardIter));
00503 }
00504 
00505 template <class _ForwardIter, class _Tp, class _Compare>
00506 inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
00507                                 const _Tp& __val, _Compare __comp) {
00508   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00509   return _STLP_PRIV __lower_bound(__first, __last, __val, __comp, __comp,
00510                                   _STLP_DISTANCE_TYPE(__first, _ForwardIter));
00511 }
00512 
00513 _STLP_MOVE_TO_PRIV_NAMESPACE
00514 
00515 template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
00516 _ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
00517                            _Compare1 __comp1, _Compare2 __comp2, _Distance*);
00518 
00519 _STLP_MOVE_TO_STD_NAMESPACE
00520 
00521 template <class _ForwardIter, class _Tp>
00522 inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
00523                                 const _Tp& __val) {
00524   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00525   return _STLP_PRIV __upper_bound(__first, __last, __val,
00526                                   _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
00527                                   _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
00528                                   _STLP_DISTANCE_TYPE(__first, _ForwardIter));
00529 }
00530 
00531 template <class _ForwardIter, class _Tp, class _Compare>
00532 inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
00533                                 const _Tp& __val, _Compare __comp) {
00534   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00535   return _STLP_PRIV __upper_bound(__first, __last, __val, __comp, __comp,
00536                                   _STLP_DISTANCE_TYPE(__first, _ForwardIter));
00537 }
00538 
00539 _STLP_MOVE_TO_PRIV_NAMESPACE
00540 
00541 template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
00542 pair<_ForwardIter, _ForwardIter>
00543 __equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
00544               _Compare1 __comp1, _Compare2 __comp2, _Distance*);
00545 
00546 _STLP_MOVE_TO_STD_NAMESPACE
00547 
00548 template <class _ForwardIter, class _Tp>
00549 inline pair<_ForwardIter, _ForwardIter>
00550 equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
00551   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00552   return _STLP_PRIV __equal_range(__first, __last, __val,
00553                                   _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
00554                                   _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
00555                                   _STLP_DISTANCE_TYPE(__first, _ForwardIter));
00556 }
00557 
00558 template <class _ForwardIter, class _Tp, class _Compare>
00559 inline pair<_ForwardIter, _ForwardIter>
00560 equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
00561             _Compare __comp) {
00562   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00563   return _STLP_PRIV __equal_range(__first, __last, __val, __comp, __comp,
00564                                   _STLP_DISTANCE_TYPE(__first, _ForwardIter));
00565 }
00566 
00567 template <class _ForwardIter, class _Tp>
00568 inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
00569                    const _Tp& __val) {
00570   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00571   _ForwardIter __i = _STLP_PRIV __lower_bound(__first, __last, __val,
00572                                               _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
00573                                               _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
00574                                               _STLP_DISTANCE_TYPE(__first, _ForwardIter));
00575   return __i != __last && !(__val < *__i);
00576 }
00577 
00578 template <class _ForwardIter, class _Tp, class _Compare>
00579 inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
00580                           const _Tp& __val,
00581                           _Compare __comp) {
00582   _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00583   _ForwardIter __i = _STLP_PRIV __lower_bound(__first, __last, __val, __comp, __comp,
00584                                               _STLP_DISTANCE_TYPE(__first, _ForwardIter));
00585   return __i != __last && !__comp(__val, *__i);
00586 }
00587 
00588 // merge, with and without an explicitly supplied comparison function.
00589 
00590 template <class _InputIter1, class _InputIter2, class _OutputIter>
00591 _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
00592                   _InputIter2 __first2, _InputIter2 __last2,
00593                   _OutputIter __result);
00594 
00595 template <class _InputIter1, class _InputIter2, class _OutputIter,
00596           class _Compare>
00597 _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
00598                   _InputIter2 __first2, _InputIter2 __last2,
00599                   _OutputIter __result, _Compare __comp);
00600 
00601 
00602 // inplace_merge and its auxiliary functions.
00603 
00604 
00605 template <class _BidirectionalIter>
00606 void inplace_merge(_BidirectionalIter __first,
00607                    _BidirectionalIter __middle,
00608                    _BidirectionalIter __last) ;
00609 
00610 template <class _BidirectionalIter, class _Compare>
00611 void inplace_merge(_BidirectionalIter __first,
00612                    _BidirectionalIter __middle,
00613                    _BidirectionalIter __last, _Compare __comp);
00614 
00615 // Set algorithms: includes, set_union, set_intersection, set_difference,
00616 // set_symmetric_difference.  All of these algorithms have the precondition
00617 // that their input ranges are sorted and the postcondition that their output
00618 // ranges are sorted.
00619 
00620 template <class _InputIter1, class _InputIter2>
00621 bool includes(_InputIter1 __first1, _InputIter1 __last1,
00622               _InputIter2 __first2, _InputIter2 __last2);
00623 
00624 template <class _InputIter1, class _InputIter2, class _Compare>
00625 bool includes(_InputIter1 __first1, _InputIter1 __last1,
00626               _InputIter2 __first2, _InputIter2 __last2, _Compare __comp);
00627 
00628 template <class _InputIter1, class _InputIter2, class _OutputIter>
00629 _OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
00630                       _InputIter2 __first2, _InputIter2 __last2,
00631                       _OutputIter __result);
00632 
00633 template <class _InputIter1, class _InputIter2, class _OutputIter,
00634           class _Compare>
00635 _OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
00636                       _InputIter2 __first2, _InputIter2 __last2,
00637                       _OutputIter __result, _Compare __comp);
00638 
00639 template <class _InputIter1, class _InputIter2, class _OutputIter>
00640 _OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
00641                              _InputIter2 __first2, _InputIter2 __last2,
00642                              _OutputIter __result);
00643 
00644 template <class _InputIter1, class _InputIter2, class _OutputIter,
00645           class _Compare>
00646 _OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
00647                              _InputIter2 __first2, _InputIter2 __last2,
00648                              _OutputIter __result, _Compare __comp);
00649 
00650 
00651 
00652 template <class _InputIter1, class _InputIter2, class _OutputIter>
00653 _OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
00654                            _InputIter2 __first2, _InputIter2 __last2,
00655                            _OutputIter __result);
00656 
00657 template <class _InputIter1, class _InputIter2, class _OutputIter,
00658           class _Compare>
00659 _OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
00660                            _InputIter2 __first2, _InputIter2 __last2,
00661                            _OutputIter __result, _Compare __comp);
00662 
00663 template <class _InputIter1, class _InputIter2, class _OutputIter>
00664 _OutputIter
00665 set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
00666                          _InputIter2 __first2, _InputIter2 __last2,
00667                          _OutputIter __result);
00668 
00669 
00670 template <class _InputIter1, class _InputIter2, class _OutputIter,
00671           class _Compare>
00672 _OutputIter
00673 set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
00674                          _InputIter2 __first2, _InputIter2 __last2,
00675                          _OutputIter __result,
00676                          _Compare __comp);
00677 
00678 
00679 // min_element and max_element, with and without an explicitly supplied
00680 // comparison function.
00681 
00682 template <class _ForwardIter>
00683 _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last);
00684 template <class _ForwardIter, class _Compare>
00685 _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last,
00686                             _Compare __comp);
00687 
00688 template <class _ForwardIter>
00689 _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last);
00690 
00691 template <class _ForwardIter, class _Compare>
00692 _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last,
00693                             _Compare __comp);
00694 
00695 // next_permutation and prev_permutation, with and without an explicitly
00696 // supplied comparison function.
00697 
00698 template <class _BidirectionalIter>
00699 bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
00700 
00701 template <class _BidirectionalIter, class _Compare>
00702 bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
00703                       _Compare __comp);
00704 
00705 
00706 template <class _BidirectionalIter>
00707 bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
00708 
00709 
00710 template <class _BidirectionalIter, class _Compare>
00711 bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
00712                       _Compare __comp);
00713 
00714 #if !defined (_STLP_NO_EXTENSIONS)
00715 // is_heap, a predicate testing whether or not a range is
00716 // a heap.  This function is an extension, not part of the C++
00717 // standard.
00718 
00719 template <class _RandomAccessIter>
00720 bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last);
00721 
00722 template <class _RandomAccessIter, class _StrictWeakOrdering>
00723 bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last,
00724              _StrictWeakOrdering __comp);
00725 
00726 // is_sorted, a predicated testing whether a range is sorted in
00727 // nondescending order.  This is an extension, not part of the C++
00728 // standard.
00729 _STLP_MOVE_TO_PRIV_NAMESPACE
00730 
00731 template <class _ForwardIter, class _StrictWeakOrdering>
00732 bool __is_sorted(_ForwardIter __first, _ForwardIter __last,
00733                  _StrictWeakOrdering __comp);
00734 
00735 _STLP_MOVE_TO_STD_NAMESPACE
00736 template <class _ForwardIter>
00737 inline bool is_sorted(_ForwardIter __first, _ForwardIter __last) {
00738   return _STLP_PRIV __is_sorted(__first, __last,
00739                                 _STLP_PRIV __less(_STLP_VALUE_TYPE(__first, _ForwardIter)));
00740 }
00741 
00742 template <class _ForwardIter, class _StrictWeakOrdering>
00743 inline bool is_sorted(_ForwardIter __first, _ForwardIter __last,
00744                       _StrictWeakOrdering __comp) {
00745   return _STLP_PRIV __is_sorted(__first, __last, __comp);
00746 }
00747 #endif
00748 
00749 _STLP_END_NAMESPACE
00750 
00751 #if !defined (_STLP_LINK_TIME_INSTANTIATION)
00752 #  include <stl/_algo.c>
00753 #endif
00754 
00755 #endif /* _STLP_INTERNAL_ALGO_H */
00756 
00757 // Local Variables:
00758 // mode:C++
00759 // End:
00760 



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