4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
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.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_ALGO_H
31 #define _STLP_INTERNAL_ALGO_H
33 #ifndef _STLP_INTERNAL_ALGOBASE_H
34 # include <stl/_algobase.h>
37 #ifndef _STLP_INTERNAL_HEAP_H
38 # include <stl/_heap.h>
41 #ifndef _STLP_INTERNAL_ITERATOR_H
42 # include <stl/_iterator.h>
45 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
46 # include <stl/_function_base.h>
49 #if defined (__SUNPRO_CC) && !defined (_STLP_INTERNAL_CSTDIO)
51 # include <stl/_cstdio.h>
56 // for_each. Apply a function to every element of a range.
57 template <class _InputIter, class _Function>
58 _STLP_INLINE_LOOP _Function
59 for_each(_InputIter __first, _InputIter __last, _Function __f) {
60 for ( ; __first != __last; ++__first)
66 template <class _InputIter, class _Predicate>
67 _STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
68 count_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) {
80 template <class _ForwardIter, class _BinaryPredicate>
81 _STLP_INLINE_LOOP _ForwardIter
82 adjacent_find(_ForwardIter __first, _ForwardIter __last,
83 _BinaryPredicate __binary_pred) {
84 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
85 if (__first == __last)
87 _ForwardIter __next = __first;
88 while(++__next != __last) {
89 if (__binary_pred(*__first, *__next))
96 template <class _ForwardIter>
97 _STLP_INLINE_LOOP _ForwardIter
98 adjacent_find(_ForwardIter __first, _ForwardIter __last) {
99 return adjacent_find(__first, __last,
100 _STLP_PRIV __equal_to(_STLP_VALUE_TYPE(__first, _ForwardIter)));
103 #if !defined (_STLP_NO_ANACHRONISMS)
104 template <class _InputIter, class _Tp, class _Size>
105 _STLP_INLINE_LOOP void
106 count(_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)
113 template <class _InputIter, class _Predicate, class _Size>
114 _STLP_INLINE_LOOP void
115 count_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))
123 template <class _ForwardIter1, class _ForwardIter2>
124 _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
125 _ForwardIter2 __first2, _ForwardIter2 __last2);
127 // search_n. Search for __count consecutive copies of __val.
128 template <class _ForwardIter, class _Integer, class _Tp>
129 _ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
130 _Integer __count, const _Tp& __val);
131 template <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);
135 template <class _InputIter, class _ForwardIter>
136 inline _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)));
144 template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
146 find_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);
153 template <class _ForwardIter1, class _ForwardIter2>
155 find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
156 _ForwardIter2 __first2, _ForwardIter2 __last2);
159 template <class _ForwardIter1, class _ForwardIter2>
160 _STLP_INLINE_LOOP _ForwardIter2
161 swap_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);
169 template <class _InputIter, class _OutputIter, class _UnaryOperation>
170 _STLP_INLINE_LOOP _OutputIter
171 transform(_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);
177 template <class _InputIter1, class _InputIter2, class _OutputIter, class _BinaryOperation>
178 _STLP_INLINE_LOOP _OutputIter
179 transform(_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);
187 // replace_if, replace_copy, replace_copy_if
189 template <class _ForwardIter, class _Predicate, class _Tp>
190 _STLP_INLINE_LOOP void
191 replace_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;
198 template <class _InputIter, class _OutputIter, class _Tp>
199 _STLP_INLINE_LOOP _OutputIter
200 replace_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;
208 template <class _Iterator, class _OutputIter, class _Predicate, class _Tp>
209 _STLP_INLINE_LOOP _OutputIter
210 replace_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;
219 // generate and generate_n
221 template <class _ForwardIter, class _Generator>
222 _STLP_INLINE_LOOP void
223 generate(_ForwardIter __first, _ForwardIter __last, _Generator __gen) {
224 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
225 for ( ; __first != __last; ++__first)
229 template <class _OutputIter, class _Size, class _Generator>
230 _STLP_INLINE_LOOP void
231 generate_n(_OutputIter __first, _Size __n, _Generator __gen) {
232 for ( ; __n > 0; --__n, ++__first)
236 // remove, remove_if, remove_copy, remove_copy_if
238 template <class _InputIter, class _OutputIter, class _Tp>
239 _STLP_INLINE_LOOP _OutputIter
240 remove_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;
251 template <class _InputIter, class _OutputIter, class _Predicate>
252 _STLP_INLINE_LOOP _OutputIter
253 remove_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;
264 template <class _ForwardIter, class _Tp>
265 _STLP_INLINE_LOOP _ForwardIter
266 remove(_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)
272 _ForwardIter __next = __first;
273 return remove_copy(++__next, __last, __first, __val);
277 template <class _ForwardIter, class _Predicate>
278 _STLP_INLINE_LOOP _ForwardIter
279 remove_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 )
285 _ForwardIter __next = __first;
286 return remove_copy_if(++__next, __last, __first, __pred);
290 // unique and unique_copy
291 template <class _InputIter, class _OutputIter>
292 _OutputIter unique_copy(_InputIter __first, _InputIter __last, _OutputIter __result);
294 template <class _InputIter, class _OutputIter, class _BinaryPredicate>
295 _OutputIter unique_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
296 _BinaryPredicate __binary_pred);
298 template <class _ForwardIter>
299 inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last) {
300 __first = adjacent_find(__first, __last);
301 return unique_copy(__first, __last, __first);
304 template <class _ForwardIter, class _BinaryPredicate>
305 inline _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);
311 // reverse and reverse_copy, and their auxiliary functions
313 template <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);
321 template <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);
328 template <class _BidirectionalIter>
330 reverse(_BidirectionalIter __first, _BidirectionalIter __last) {
331 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
332 __reverse(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _BidirectionalIter));
335 template <class _BidirectionalIter, class _OutputIter>
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) {
349 _STLP_MOVE_TO_PRIV_NAMESPACE
351 // rotate and rotate_copy, and their auxiliary functions
352 template <class _EuclideanRingElement>
354 _EuclideanRingElement __gcd(_EuclideanRingElement __m,
355 _EuclideanRingElement __n) {
357 _EuclideanRingElement __t = __m % __n;
364 _STLP_MOVE_TO_STD_NAMESPACE
366 template <class _ForwardIter>
367 void rotate(_ForwardIter __first, _ForwardIter __middle, _ForwardIter __last);
369 template <class _ForwardIter, class _OutputIter>
370 inline _OutputIter rotate_copy(_ForwardIter __first, _ForwardIter __middle,
371 _ForwardIter __last, _OutputIter __result) {
372 return copy(__first, __middle, copy(__middle, __last, __result));
377 template <class _RandomAccessIter>
378 void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last);
380 template <class _RandomAccessIter, class _RandomNumberGenerator>
381 void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last,
382 _RandomNumberGenerator& __rand);
384 #if !defined (_STLP_NO_EXTENSIONS)
385 // random_sample and random_sample_n (extensions, not part of the standard).
387 template <class _ForwardIter, class _OutputIter, class _Distance>
388 _OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
389 _OutputIter __out_ite, const _Distance __n);
391 template <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);
397 template <class _InputIter, class _RandomAccessIter>
399 random_sample(_InputIter __first, _InputIter __last,
400 _RandomAccessIter __out_first, _RandomAccessIter __out_last);
402 template <class _InputIter, class _RandomAccessIter,
403 class _RandomNumberGenerator>
405 random_sample(_InputIter __first, _InputIter __last,
406 _RandomAccessIter __out_first, _RandomAccessIter __out_last,
407 _RandomNumberGenerator& __rand);
409 #endif /* _STLP_NO_EXTENSIONS */
411 // partition, stable_partition, and their auxiliary functions
413 template <class _ForwardIter, class _Predicate>
414 _ForwardIter partition(_ForwardIter __first, _ForwardIter __last, _Predicate __pred);
416 template <class _ForwardIter, class _Predicate>
418 stable_partition(_ForwardIter __first, _ForwardIter __last, _Predicate __pred);
420 // sort() and its auxiliary functions.
421 _STLP_MOVE_TO_PRIV_NAMESPACE
423 template <class _Size>
424 inline _Size __lg(_Size __n) {
426 for (__k = 0; __n != 1; __n >>= 1) ++__k;
430 _STLP_MOVE_TO_STD_NAMESPACE
432 template <class _RandomAccessIter>
433 void sort(_RandomAccessIter __first, _RandomAccessIter __last);
434 template <class _RandomAccessIter, class _Compare>
435 void sort(_RandomAccessIter __first, _RandomAccessIter __last, _Compare __comp);
437 // stable_sort() and its auxiliary functions.
438 template <class _RandomAccessIter>
439 void stable_sort(_RandomAccessIter __first,
440 _RandomAccessIter __last);
442 template <class _RandomAccessIter, class _Compare>
443 void stable_sort(_RandomAccessIter __first,
444 _RandomAccessIter __last, _Compare __comp);
446 // partial_sort, partial_sort_copy, and auxiliary functions.
448 template <class _RandomAccessIter>
449 void partial_sort(_RandomAccessIter __first, _RandomAccessIter __middle,
450 _RandomAccessIter __last);
452 template <class _RandomAccessIter, class _Compare>
453 void partial_sort(_RandomAccessIter __first,_RandomAccessIter __middle,
454 _RandomAccessIter __last, _Compare __comp);
456 template <class _InputIter, class _RandomAccessIter>
458 partial_sort_copy(_InputIter __first, _InputIter __last,
459 _RandomAccessIter __result_first, _RandomAccessIter __result_last);
461 template <class _InputIter, class _RandomAccessIter, class _Compare>
463 partial_sort_copy(_InputIter __first, _InputIter __last,
464 _RandomAccessIter __result_first,
465 _RandomAccessIter __result_last, _Compare __comp);
467 // nth_element() and its auxiliary functions.
468 template <class _RandomAccessIter>
469 void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
470 _RandomAccessIter __last);
472 template <class _RandomAccessIter, class _Compare>
473 void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
474 _RandomAccessIter __last, _Compare __comp);
476 // auxiliary class for lower_bound, etc.
477 _STLP_MOVE_TO_PRIV_NAMESPACE
479 template <class _T1, class _T2>
481 bool operator() (const _T1& __x, const _T2& __y) const { return __x < __y ; }
484 template <class _T1, class _T2>
485 __less_2<_T1,_T2> __less2(_T1*, _T2* ) { return __less_2<_T1, _T2>(); }
487 #if defined (_STLP_FUNCTION_PARTIAL_ORDER)
489 less<_Tp> __less2(_Tp*, _Tp* ) { return less<_Tp>(); }
492 _STLP_MOVE_TO_STD_NAMESPACE
494 // Binary search (lower_bound, upper_bound, equal_range, binary_search).
495 template <class _ForwardIter, class _Tp>
496 inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
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));
505 template <class _ForwardIter, class _Tp, class _Compare>
506 inline _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));
513 _STLP_MOVE_TO_PRIV_NAMESPACE
515 template <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*);
519 _STLP_MOVE_TO_STD_NAMESPACE
521 template <class _ForwardIter, class _Tp>
522 inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
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));
531 template <class _ForwardIter, class _Tp, class _Compare>
532 inline _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));
539 _STLP_MOVE_TO_PRIV_NAMESPACE
541 template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
542 pair<_ForwardIter, _ForwardIter>
543 __equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
544 _Compare1 __comp1, _Compare2 __comp2, _Distance*);
546 _STLP_MOVE_TO_STD_NAMESPACE
548 template <class _ForwardIter, class _Tp>
549 inline pair<_ForwardIter, _ForwardIter>
550 equal_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));
558 template <class _ForwardIter, class _Tp, class _Compare>
559 inline pair<_ForwardIter, _ForwardIter>
560 equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
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));
567 template <class _ForwardIter, class _Tp>
568 inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
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);
578 template <class _ForwardIter, class _Tp, class _Compare>
579 inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
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);
588 // merge, with and without an explicitly supplied comparison function.
590 template <class _InputIter1, class _InputIter2, class _OutputIter>
591 _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
592 _InputIter2 __first2, _InputIter2 __last2,
593 _OutputIter __result);
595 template <class _InputIter1, class _InputIter2, class _OutputIter,
597 _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
598 _InputIter2 __first2, _InputIter2 __last2,
599 _OutputIter __result, _Compare __comp);
602 // inplace_merge and its auxiliary functions.
605 template <class _BidirectionalIter>
606 void inplace_merge(_BidirectionalIter __first,
607 _BidirectionalIter __middle,
608 _BidirectionalIter __last) ;
610 template <class _BidirectionalIter, class _Compare>
611 void inplace_merge(_BidirectionalIter __first,
612 _BidirectionalIter __middle,
613 _BidirectionalIter __last, _Compare __comp);
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.
620 template <class _InputIter1, class _InputIter2>
621 bool includes(_InputIter1 __first1, _InputIter1 __last1,
622 _InputIter2 __first2, _InputIter2 __last2);
624 template <class _InputIter1, class _InputIter2, class _Compare>
625 bool includes(_InputIter1 __first1, _InputIter1 __last1,
626 _InputIter2 __first2, _InputIter2 __last2, _Compare __comp);
628 template <class _InputIter1, class _InputIter2, class _OutputIter>
629 _OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
630 _InputIter2 __first2, _InputIter2 __last2,
631 _OutputIter __result);
633 template <class _InputIter1, class _InputIter2, class _OutputIter,
635 _OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
636 _InputIter2 __first2, _InputIter2 __last2,
637 _OutputIter __result, _Compare __comp);
639 template <class _InputIter1, class _InputIter2, class _OutputIter>
640 _OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
641 _InputIter2 __first2, _InputIter2 __last2,
642 _OutputIter __result);
644 template <class _InputIter1, class _InputIter2, class _OutputIter,
646 _OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
647 _InputIter2 __first2, _InputIter2 __last2,
648 _OutputIter __result, _Compare __comp);
652 template <class _InputIter1, class _InputIter2, class _OutputIter>
653 _OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
654 _InputIter2 __first2, _InputIter2 __last2,
655 _OutputIter __result);
657 template <class _InputIter1, class _InputIter2, class _OutputIter,
659 _OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
660 _InputIter2 __first2, _InputIter2 __last2,
661 _OutputIter __result, _Compare __comp);
663 template <class _InputIter1, class _InputIter2, class _OutputIter>
665 set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
666 _InputIter2 __first2, _InputIter2 __last2,
667 _OutputIter __result);
670 template <class _InputIter1, class _InputIter2, class _OutputIter,
673 set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
674 _InputIter2 __first2, _InputIter2 __last2,
675 _OutputIter __result,
679 // min_element and max_element, with and without an explicitly supplied
680 // comparison function.
682 template <class _ForwardIter>
683 _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last);
684 template <class _ForwardIter, class _Compare>
685 _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last,
688 template <class _ForwardIter>
689 _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last);
691 template <class _ForwardIter, class _Compare>
692 _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last,
695 // next_permutation and prev_permutation, with and without an explicitly
696 // supplied comparison function.
698 template <class _BidirectionalIter>
699 bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
701 template <class _BidirectionalIter, class _Compare>
702 bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
706 template <class _BidirectionalIter>
707 bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
710 template <class _BidirectionalIter, class _Compare>
711 bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
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++
719 template <class _RandomAccessIter>
720 bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last);
722 template <class _RandomAccessIter, class _StrictWeakOrdering>
723 bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last,
724 _StrictWeakOrdering __comp);
726 // is_sorted, a predicated testing whether a range is sorted in
727 // nondescending order. This is an extension, not part of the C++
729 _STLP_MOVE_TO_PRIV_NAMESPACE
731 template <class _ForwardIter, class _StrictWeakOrdering>
732 bool __is_sorted(_ForwardIter __first, _ForwardIter __last,
733 _StrictWeakOrdering __comp);
735 _STLP_MOVE_TO_STD_NAMESPACE
736 template <class _ForwardIter>
737 inline bool is_sorted(_ForwardIter __first, _ForwardIter __last) {
738 return _STLP_PRIV __is_sorted(__first, __last,
739 _STLP_PRIV __less(_STLP_VALUE_TYPE(__first, _ForwardIter)));
742 template <class _ForwardIter, class _StrictWeakOrdering>
743 inline bool is_sorted(_ForwardIter __first, _ForwardIter __last,
744 _StrictWeakOrdering __comp) {
745 return _STLP_PRIV __is_sorted(__first, __last, __comp);
751 #if !defined (_STLP_LINK_TIME_INSTANTIATION)
752 # include <stl/_algo.c>
755 #endif /* _STLP_INTERNAL_ALGO_H */