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