PageRenderTime 73ms CodeModel.GetById 13ms app.highlight 54ms RepoModel.GetById 1ms app.codeStats 0ms

/project/jni/stlport/stlport/stl/_algo.h

https://github.com/aichunyu/FFPlayer
C Header | 760 lines | 553 code | 139 blank | 68 comment | 62 complexity | 8361547bf62936dfe3c75760393a8990 MD5 | raw file
  1/*
  2 *
  3 * Copyright (c) 1994
  4 * Hewlett-Packard Company
  5 *
  6 * Copyright (c) 1996,1997
  7 * Silicon Graphics Computer Systems, Inc.
  8 *
  9 * Copyright (c) 1997
 10 * Moscow Center for SPARC Technology
 11 *
 12 * Copyright (c) 1999
 13 * Boris Fomitchev
 14 *
 15 * This material is provided "as is", with absolutely no warranty expressed
 16 * or implied. Any use is at your own risk.
 17 *
 18 * Permission to use or copy this software for any purpose is hereby granted
 19 * without fee, provided the above notices are retained on all copies.
 20 * Permission to modify the code and to distribute modified code is granted,
 21 * provided the above notices are retained, and a notice that the code was
 22 * modified is included with the above copyright notice.
 23 *
 24 */
 25
 26/* NOTE: This is an internal header file, included by other STL headers.
 27 *   You should not attempt to use it directly.
 28 */
 29
 30#ifndef _STLP_INTERNAL_ALGO_H
 31#define _STLP_INTERNAL_ALGO_H
 32
 33#ifndef _STLP_INTERNAL_ALGOBASE_H
 34#  include <stl/_algobase.h>
 35#endif
 36
 37#ifndef _STLP_INTERNAL_HEAP_H
 38#  include <stl/_heap.h>
 39#endif
 40
 41#ifndef _STLP_INTERNAL_ITERATOR_H
 42#  include <stl/_iterator.h>
 43#endif
 44
 45#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
 46#  include <stl/_function_base.h>
 47#endif
 48
 49#if defined (__SUNPRO_CC) && !defined (_STLP_INTERNAL_CSTDIO)
 50// remove() conflict
 51#  include <stl/_cstdio.h>
 52#endif
 53
 54_STLP_BEGIN_NAMESPACE
 55
 56// for_each.  Apply a function to every element of a range.
 57template <class _InputIter, class _Function>
 58_STLP_INLINE_LOOP _Function
 59for_each(_InputIter __first, _InputIter __last, _Function __f) {
 60  for ( ; __first != __last; ++__first)
 61    __f(*__first);
 62  return __f;
 63}
 64
 65// count_if
 66template <class _InputIter, class _Predicate>
 67_STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
 68count_if(_InputIter __first, _InputIter __last, _Predicate __pred) {
 69  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
 70  _STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
 71  for ( ; __first != __last; ++__first) {
 72    if (__pred(*__first))
 73      ++__n;
 74  }
 75  return __n;
 76}
 77
 78// adjacent_find.
 79
 80template <class _ForwardIter, class _BinaryPredicate>
 81_STLP_INLINE_LOOP _ForwardIter
 82adjacent_find(_ForwardIter __first, _ForwardIter __last,
 83              _BinaryPredicate __binary_pred) {
 84  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
 85  if (__first == __last)
 86    return __last;
 87  _ForwardIter __next = __first;
 88  while(++__next != __last) {
 89    if (__binary_pred(*__first, *__next))
 90      return __first;
 91    __first = __next;
 92  }
 93  return __last;
 94}
 95
 96template <class _ForwardIter>
 97_STLP_INLINE_LOOP _ForwardIter
 98adjacent_find(_ForwardIter __first, _ForwardIter __last) {
 99  return adjacent_find(__first, __last,
100                       _STLP_PRIV __equal_to(_STLP_VALUE_TYPE(__first, _ForwardIter)));
101}
102
103#if !defined (_STLP_NO_ANACHRONISMS)
104template <class _InputIter, class _Tp, class _Size>
105_STLP_INLINE_LOOP void
106count(_InputIter __first, _InputIter __last, const _Tp& __val, _Size& __n) {
107  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
108    for ( ; __first != __last; ++__first)
109      if (*__first == __val)
110        ++__n;
111}
112
113template <class _InputIter, class _Predicate, class _Size>
114_STLP_INLINE_LOOP void
115count_if(_InputIter __first, _InputIter __last, _Predicate __pred, _Size& __n) {
116  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
117  for ( ; __first != __last; ++__first)
118    if (__pred(*__first))
119      ++__n;
120}
121#endif
122
123template <class _ForwardIter1, class _ForwardIter2>
124_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
125                     _ForwardIter2 __first2, _ForwardIter2 __last2);
126
127// search_n.  Search for __count consecutive copies of __val.
128template <class _ForwardIter, class _Integer, class _Tp>
129_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
130                      _Integer __count, const _Tp& __val);
131template <class _ForwardIter, class _Integer, class _Tp, class _BinaryPred>
132_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
133                      _Integer __count, const _Tp& __val, _BinaryPred __binary_pred);
134
135template <class _InputIter, class _ForwardIter>
136inline _InputIter find_first_of(_InputIter __first1, _InputIter __last1,
137                                _ForwardIter __first2, _ForwardIter __last2) {
138  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
139  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
140  return _STLP_PRIV __find_first_of(__first1, __last1, __first2, __last2,
141                                    _STLP_PRIV __equal_to(_STLP_VALUE_TYPE(__first1, _InputIter)));
142}
143
144template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
145inline _InputIter
146find_first_of(_InputIter __first1, _InputIter __last1,
147              _ForwardIter __first2, _ForwardIter __last2, _BinaryPredicate __comp) {
148  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
149  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
150  return _STLP_PRIV __find_first_of(__first1, __last1, __first2, __last2, __comp);
151}
152
153template <class _ForwardIter1, class _ForwardIter2>
154_ForwardIter1
155find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
156         _ForwardIter2 __first2, _ForwardIter2 __last2);
157
158// swap_ranges
159template <class _ForwardIter1, class _ForwardIter2>
160_STLP_INLINE_LOOP _ForwardIter2
161swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 __first2) {
162  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
163  for ( ; __first1 != __last1; ++__first1, ++__first2)
164    iter_swap(__first1, __first2);
165  return __first2;
166}
167
168// transform
169template <class _InputIter, class _OutputIter, class _UnaryOperation>
170_STLP_INLINE_LOOP _OutputIter
171transform(_InputIter __first, _InputIter __last, _OutputIter __result, _UnaryOperation __opr) {
172  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
173  for ( ; __first != __last; ++__first, ++__result)
174    *__result = __opr(*__first);
175  return __result;
176}
177template <class _InputIter1, class _InputIter2, class _OutputIter, class _BinaryOperation>
178_STLP_INLINE_LOOP _OutputIter
179transform(_InputIter1 __first1, _InputIter1 __last1,
180          _InputIter2 __first2, _OutputIter __result,_BinaryOperation __binary_op) {
181  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
182  for ( ; __first1 != __last1; ++__first1, ++__first2, ++__result)
183    *__result = __binary_op(*__first1, *__first2);
184  return __result;
185}
186
187// replace_if, replace_copy, replace_copy_if
188
189template <class _ForwardIter, class _Predicate, class _Tp>
190_STLP_INLINE_LOOP void
191replace_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred, const _Tp& __new_value) {
192  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
193  for ( ; __first != __last; ++__first)
194    if (__pred(*__first))
195      *__first = __new_value;
196}
197
198template <class _InputIter, class _OutputIter, class _Tp>
199_STLP_INLINE_LOOP  _OutputIter
200replace_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
201             const _Tp& __old_value, const _Tp& __new_value) {
202  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
203  for ( ; __first != __last; ++__first, ++__result)
204    *__result = *__first == __old_value ? __new_value : *__first;
205  return __result;
206}
207
208template <class _Iterator, class _OutputIter, class _Predicate, class _Tp>
209_STLP_INLINE_LOOP _OutputIter
210replace_copy_if(_Iterator __first, _Iterator __last,
211                _OutputIter __result,
212                _Predicate __pred, const _Tp& __new_value) {
213  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
214  for ( ; __first != __last; ++__first, ++__result)
215    *__result = __pred(*__first) ? __new_value : *__first;
216  return __result;
217}
218
219// generate and generate_n
220
221template <class _ForwardIter, class _Generator>
222_STLP_INLINE_LOOP void
223generate(_ForwardIter __first, _ForwardIter __last, _Generator __gen) {
224  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
225  for ( ; __first != __last; ++__first)
226    *__first = __gen();
227}
228
229template <class _OutputIter, class _Size, class _Generator>
230_STLP_INLINE_LOOP void
231generate_n(_OutputIter __first, _Size __n, _Generator __gen) {
232  for ( ; __n > 0; --__n, ++__first)
233    *__first = __gen();
234}
235
236// remove, remove_if, remove_copy, remove_copy_if
237
238template <class _InputIter, class _OutputIter, class _Tp>
239_STLP_INLINE_LOOP _OutputIter
240remove_copy(_InputIter __first, _InputIter __last,_OutputIter __result, const _Tp& __val) {
241  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
242  for ( ; __first != __last; ++__first) {
243    if (!(*__first == __val)) {
244      *__result = *__first;
245      ++__result;
246    }
247  }
248  return __result;
249}
250
251template <class _InputIter, class _OutputIter, class _Predicate>
252_STLP_INLINE_LOOP _OutputIter
253remove_copy_if(_InputIter __first, _InputIter __last, _OutputIter __result, _Predicate __pred) {
254  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
255  for ( ; __first != __last; ++__first) {
256    if (!__pred(*__first)) {
257      *__result = *__first;
258      ++__result;
259    }
260  }
261  return __result;
262}
263
264template <class _ForwardIter, class _Tp>
265_STLP_INLINE_LOOP _ForwardIter
266remove(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
267  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
268  __first = find(__first, __last, __val);
269  if (__first == __last)
270    return __first;
271  else {
272    _ForwardIter __next = __first;
273    return remove_copy(++__next, __last, __first, __val);
274  }
275}
276
277template <class _ForwardIter, class _Predicate>
278_STLP_INLINE_LOOP _ForwardIter
279remove_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred) {
280  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
281  __first = find_if(__first, __last, __pred);
282  if ( __first == __last )
283    return __first;
284  else {
285    _ForwardIter __next = __first;
286    return remove_copy_if(++__next, __last, __first, __pred);
287  }
288}
289
290// unique and unique_copy
291template <class _InputIter, class _OutputIter>
292_OutputIter unique_copy(_InputIter __first, _InputIter __last, _OutputIter __result);
293
294template <class _InputIter, class _OutputIter, class _BinaryPredicate>
295_OutputIter unique_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
296                        _BinaryPredicate __binary_pred);
297
298template <class _ForwardIter>
299inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last) {
300  __first = adjacent_find(__first, __last);
301  return unique_copy(__first, __last, __first);
302}
303
304template <class _ForwardIter, class _BinaryPredicate>
305inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last,
306                           _BinaryPredicate __binary_pred) {
307  __first = adjacent_find(__first, __last, __binary_pred);
308  return unique_copy(__first, __last, __first, __binary_pred);
309}
310
311// reverse and reverse_copy, and their auxiliary functions
312
313template <class _BidirectionalIter>
314_STLP_INLINE_LOOP void
315__reverse(_BidirectionalIter __first, _BidirectionalIter __last, const bidirectional_iterator_tag &) {
316  for (; __first != __last && __first != --__last; ++__first)
317    iter_swap(__first,__last);
318}
319
320
321template <class _RandomAccessIter>
322_STLP_INLINE_LOOP void
323__reverse(_RandomAccessIter __first, _RandomAccessIter __last, const random_access_iterator_tag &) {
324  for (; __first < __last; ++__first)
325    iter_swap(__first, --__last);
326}
327
328template <class _BidirectionalIter>
329inline void
330reverse(_BidirectionalIter __first, _BidirectionalIter __last) {
331  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
332  __reverse(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _BidirectionalIter));
333}
334
335template <class _BidirectionalIter, class _OutputIter>
336_STLP_INLINE_LOOP
337_OutputIter reverse_copy(_BidirectionalIter __first,
338                         _BidirectionalIter __last,
339                         _OutputIter __result) {
340  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
341  while (__first != __last) {
342    --__last;
343    *__result = *__last;
344    ++__result;
345  }
346  return __result;
347}
348
349_STLP_MOVE_TO_PRIV_NAMESPACE
350
351// rotate and rotate_copy, and their auxiliary functions
352template <class _EuclideanRingElement>
353_STLP_INLINE_LOOP
354_EuclideanRingElement __gcd(_EuclideanRingElement __m,
355                            _EuclideanRingElement __n) {
356  while (__n != 0) {
357    _EuclideanRingElement __t = __m % __n;
358    __m = __n;
359    __n = __t;
360  }
361  return __m;
362}
363
364_STLP_MOVE_TO_STD_NAMESPACE
365
366template <class _ForwardIter>
367void rotate(_ForwardIter __first, _ForwardIter __middle, _ForwardIter __last);
368
369template <class _ForwardIter, class _OutputIter>
370inline _OutputIter rotate_copy(_ForwardIter __first, _ForwardIter __middle,
371                               _ForwardIter __last, _OutputIter __result) {
372  return copy(__first, __middle, copy(__middle, __last, __result));
373}
374
375// random_shuffle
376
377template <class _RandomAccessIter>
378void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last);
379
380template <class _RandomAccessIter, class _RandomNumberGenerator>
381void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last,
382                    _RandomNumberGenerator& __rand);
383
384#if !defined (_STLP_NO_EXTENSIONS)
385// random_sample and random_sample_n (extensions, not part of the standard).
386
387template <class _ForwardIter, class _OutputIter, class _Distance>
388_OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
389                            _OutputIter __out_ite, const _Distance __n);
390
391template <class _ForwardIter, class _OutputIter, class _Distance,
392          class _RandomNumberGenerator>
393_OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
394                            _OutputIter __out_ite, const _Distance __n,
395                            _RandomNumberGenerator& __rand);
396
397template <class _InputIter, class _RandomAccessIter>
398_RandomAccessIter
399random_sample(_InputIter __first, _InputIter __last,
400              _RandomAccessIter __out_first, _RandomAccessIter __out_last);
401
402template <class _InputIter, class _RandomAccessIter,
403          class _RandomNumberGenerator>
404_RandomAccessIter
405random_sample(_InputIter __first, _InputIter __last,
406              _RandomAccessIter __out_first, _RandomAccessIter __out_last,
407              _RandomNumberGenerator& __rand);
408
409#endif /* _STLP_NO_EXTENSIONS */
410
411// partition, stable_partition, and their auxiliary functions
412
413template <class _ForwardIter, class _Predicate>
414_ForwardIter partition(_ForwardIter __first, _ForwardIter __last, _Predicate   __pred);
415
416template <class _ForwardIter, class _Predicate>
417_ForwardIter
418stable_partition(_ForwardIter __first, _ForwardIter __last, _Predicate __pred);
419
420// sort() and its auxiliary functions.
421_STLP_MOVE_TO_PRIV_NAMESPACE
422
423template <class _Size>
424inline _Size __lg(_Size __n) {
425  _Size __k;
426  for (__k = 0; __n != 1; __n >>= 1) ++__k;
427  return __k;
428}
429
430_STLP_MOVE_TO_STD_NAMESPACE
431
432template <class _RandomAccessIter>
433void sort(_RandomAccessIter __first, _RandomAccessIter __last);
434template <class _RandomAccessIter, class _Compare>
435void sort(_RandomAccessIter __first, _RandomAccessIter __last, _Compare __comp);
436
437// stable_sort() and its auxiliary functions.
438template <class _RandomAccessIter>
439void stable_sort(_RandomAccessIter __first,
440                 _RandomAccessIter __last);
441
442template <class _RandomAccessIter, class _Compare>
443void stable_sort(_RandomAccessIter __first,
444                 _RandomAccessIter __last, _Compare __comp);
445
446// partial_sort, partial_sort_copy, and auxiliary functions.
447
448template <class _RandomAccessIter>
449void partial_sort(_RandomAccessIter __first, _RandomAccessIter __middle,
450                  _RandomAccessIter __last);
451
452template <class _RandomAccessIter, class _Compare>
453void partial_sort(_RandomAccessIter __first,_RandomAccessIter __middle,
454                  _RandomAccessIter __last, _Compare __comp);
455
456template <class _InputIter, class _RandomAccessIter>
457_RandomAccessIter
458partial_sort_copy(_InputIter __first, _InputIter __last,
459                  _RandomAccessIter __result_first, _RandomAccessIter __result_last);
460
461template <class _InputIter, class _RandomAccessIter, class _Compare>
462_RandomAccessIter
463partial_sort_copy(_InputIter __first, _InputIter __last,
464                  _RandomAccessIter __result_first,
465                  _RandomAccessIter __result_last, _Compare __comp);
466
467// nth_element() and its auxiliary functions.
468template <class _RandomAccessIter>
469void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
470                 _RandomAccessIter __last);
471
472template <class _RandomAccessIter, class _Compare>
473void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
474                 _RandomAccessIter __last, _Compare __comp);
475
476// auxiliary class for lower_bound, etc.
477_STLP_MOVE_TO_PRIV_NAMESPACE
478
479template <class _T1, class _T2>
480struct __less_2 {
481  bool operator() (const _T1& __x, const _T2& __y) const { return __x < __y ; }
482};
483
484template <class _T1, class _T2>
485__less_2<_T1,_T2> __less2(_T1*, _T2* ) { return __less_2<_T1, _T2>(); }
486
487#if defined (_STLP_FUNCTION_PARTIAL_ORDER)
488template <class _Tp>
489less<_Tp> __less2(_Tp*, _Tp* ) { return less<_Tp>(); }
490#endif
491
492_STLP_MOVE_TO_STD_NAMESPACE
493
494// Binary search (lower_bound, upper_bound, equal_range, binary_search).
495template <class _ForwardIter, class _Tp>
496inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
497                                   const _Tp& __val) {
498  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
499  return _STLP_PRIV __lower_bound(__first, __last, __val,
500                                  _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
501                                  _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
502                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
503}
504
505template <class _ForwardIter, class _Tp, class _Compare>
506inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
507                                const _Tp& __val, _Compare __comp) {
508  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
509  return _STLP_PRIV __lower_bound(__first, __last, __val, __comp, __comp,
510                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
511}
512
513_STLP_MOVE_TO_PRIV_NAMESPACE
514
515template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
516_ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
517                           _Compare1 __comp1, _Compare2 __comp2, _Distance*);
518
519_STLP_MOVE_TO_STD_NAMESPACE
520
521template <class _ForwardIter, class _Tp>
522inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
523                                const _Tp& __val) {
524  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
525  return _STLP_PRIV __upper_bound(__first, __last, __val,
526                                  _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
527                                  _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
528                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
529}
530
531template <class _ForwardIter, class _Tp, class _Compare>
532inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
533                                const _Tp& __val, _Compare __comp) {
534  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
535  return _STLP_PRIV __upper_bound(__first, __last, __val, __comp, __comp,
536                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
537}
538
539_STLP_MOVE_TO_PRIV_NAMESPACE
540
541template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
542pair<_ForwardIter, _ForwardIter>
543__equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
544              _Compare1 __comp1, _Compare2 __comp2, _Distance*);
545
546_STLP_MOVE_TO_STD_NAMESPACE
547
548template <class _ForwardIter, class _Tp>
549inline pair<_ForwardIter, _ForwardIter>
550equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
551  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
552  return _STLP_PRIV __equal_range(__first, __last, __val,
553                                  _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
554                                  _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
555                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
556}
557
558template <class _ForwardIter, class _Tp, class _Compare>
559inline pair<_ForwardIter, _ForwardIter>
560equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
561            _Compare __comp) {
562  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
563  return _STLP_PRIV __equal_range(__first, __last, __val, __comp, __comp,
564                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
565}
566
567template <class _ForwardIter, class _Tp>
568inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
569                   const _Tp& __val) {
570  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
571  _ForwardIter __i = _STLP_PRIV __lower_bound(__first, __last, __val,
572                                              _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
573                                              _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
574                                              _STLP_DISTANCE_TYPE(__first, _ForwardIter));
575  return __i != __last && !(__val < *__i);
576}
577
578template <class _ForwardIter, class _Tp, class _Compare>
579inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
580                          const _Tp& __val,
581                          _Compare __comp) {
582  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
583  _ForwardIter __i = _STLP_PRIV __lower_bound(__first, __last, __val, __comp, __comp,
584                                              _STLP_DISTANCE_TYPE(__first, _ForwardIter));
585  return __i != __last && !__comp(__val, *__i);
586}
587
588// merge, with and without an explicitly supplied comparison function.
589
590template <class _InputIter1, class _InputIter2, class _OutputIter>
591_OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
592                  _InputIter2 __first2, _InputIter2 __last2,
593                  _OutputIter __result);
594
595template <class _InputIter1, class _InputIter2, class _OutputIter,
596          class _Compare>
597_OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
598                  _InputIter2 __first2, _InputIter2 __last2,
599                  _OutputIter __result, _Compare __comp);
600
601
602// inplace_merge and its auxiliary functions.
603
604
605template <class _BidirectionalIter>
606void inplace_merge(_BidirectionalIter __first,
607                   _BidirectionalIter __middle,
608                   _BidirectionalIter __last) ;
609
610template <class _BidirectionalIter, class _Compare>
611void inplace_merge(_BidirectionalIter __first,
612                   _BidirectionalIter __middle,
613                   _BidirectionalIter __last, _Compare __comp);
614
615// Set algorithms: includes, set_union, set_intersection, set_difference,
616// set_symmetric_difference.  All of these algorithms have the precondition
617// that their input ranges are sorted and the postcondition that their output
618// ranges are sorted.
619
620template <class _InputIter1, class _InputIter2>
621bool includes(_InputIter1 __first1, _InputIter1 __last1,
622              _InputIter2 __first2, _InputIter2 __last2);
623
624template <class _InputIter1, class _InputIter2, class _Compare>
625bool includes(_InputIter1 __first1, _InputIter1 __last1,
626              _InputIter2 __first2, _InputIter2 __last2, _Compare __comp);
627
628template <class _InputIter1, class _InputIter2, class _OutputIter>
629_OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
630                      _InputIter2 __first2, _InputIter2 __last2,
631                      _OutputIter __result);
632
633template <class _InputIter1, class _InputIter2, class _OutputIter,
634          class _Compare>
635_OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
636                      _InputIter2 __first2, _InputIter2 __last2,
637                      _OutputIter __result, _Compare __comp);
638
639template <class _InputIter1, class _InputIter2, class _OutputIter>
640_OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
641                             _InputIter2 __first2, _InputIter2 __last2,
642                             _OutputIter __result);
643
644template <class _InputIter1, class _InputIter2, class _OutputIter,
645          class _Compare>
646_OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
647                             _InputIter2 __first2, _InputIter2 __last2,
648                             _OutputIter __result, _Compare __comp);
649
650
651
652template <class _InputIter1, class _InputIter2, class _OutputIter>
653_OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
654                           _InputIter2 __first2, _InputIter2 __last2,
655                           _OutputIter __result);
656
657template <class _InputIter1, class _InputIter2, class _OutputIter,
658          class _Compare>
659_OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
660                           _InputIter2 __first2, _InputIter2 __last2,
661                           _OutputIter __result, _Compare __comp);
662
663template <class _InputIter1, class _InputIter2, class _OutputIter>
664_OutputIter
665set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
666                         _InputIter2 __first2, _InputIter2 __last2,
667                         _OutputIter __result);
668
669
670template <class _InputIter1, class _InputIter2, class _OutputIter,
671          class _Compare>
672_OutputIter
673set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
674                         _InputIter2 __first2, _InputIter2 __last2,
675                         _OutputIter __result,
676                         _Compare __comp);
677
678
679// min_element and max_element, with and without an explicitly supplied
680// comparison function.
681
682template <class _ForwardIter>
683_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last);
684template <class _ForwardIter, class _Compare>
685_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last,
686                            _Compare __comp);
687
688template <class _ForwardIter>
689_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last);
690
691template <class _ForwardIter, class _Compare>
692_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last,
693                            _Compare __comp);
694
695// next_permutation and prev_permutation, with and without an explicitly
696// supplied comparison function.
697
698template <class _BidirectionalIter>
699bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
700
701template <class _BidirectionalIter, class _Compare>
702bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
703                      _Compare __comp);
704
705
706template <class _BidirectionalIter>
707bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
708
709
710template <class _BidirectionalIter, class _Compare>
711bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
712                      _Compare __comp);
713
714#if !defined (_STLP_NO_EXTENSIONS)
715// is_heap, a predicate testing whether or not a range is
716// a heap.  This function is an extension, not part of the C++
717// standard.
718
719template <class _RandomAccessIter>
720bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last);
721
722template <class _RandomAccessIter, class _StrictWeakOrdering>
723bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last,
724             _StrictWeakOrdering __comp);
725
726// is_sorted, a predicated testing whether a range is sorted in
727// nondescending order.  This is an extension, not part of the C++
728// standard.
729_STLP_MOVE_TO_PRIV_NAMESPACE
730
731template <class _ForwardIter, class _StrictWeakOrdering>
732bool __is_sorted(_ForwardIter __first, _ForwardIter __last,
733                 _StrictWeakOrdering __comp);
734
735_STLP_MOVE_TO_STD_NAMESPACE
736template <class _ForwardIter>
737inline bool is_sorted(_ForwardIter __first, _ForwardIter __last) {
738  return _STLP_PRIV __is_sorted(__first, __last,
739                                _STLP_PRIV __less(_STLP_VALUE_TYPE(__first, _ForwardIter)));
740}
741
742template <class _ForwardIter, class _StrictWeakOrdering>
743inline bool is_sorted(_ForwardIter __first, _ForwardIter __last,
744                      _StrictWeakOrdering __comp) {
745  return _STLP_PRIV __is_sorted(__first, __last, __comp);
746}
747#endif
748
749_STLP_END_NAMESPACE
750
751#if !defined (_STLP_LINK_TIME_INSTANTIATION)
752#  include <stl/_algo.c>
753#endif
754
755#endif /* _STLP_INTERNAL_ALGO_H */
756
757// Local Variables:
758// mode:C++
759// End:
760