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_ALGOBASE_H
31*c2c66affSColin Finck #define _STLP_INTERNAL_ALGOBASE_H
32*c2c66affSColin Finck
33*c2c66affSColin Finck #ifndef _STLP_INTERNAL_CSTDDEF
34*c2c66affSColin Finck # include <stl/_cstddef.h>
35*c2c66affSColin Finck #endif
36*c2c66affSColin Finck
37*c2c66affSColin Finck #ifndef _STLP_INTERNAL_CSTRING
38*c2c66affSColin Finck # include <stl/_cstring.h>
39*c2c66affSColin Finck #endif
40*c2c66affSColin Finck
41*c2c66affSColin Finck #ifndef _STLP_CLIMITS
42*c2c66affSColin Finck # include <climits>
43*c2c66affSColin Finck #endif
44*c2c66affSColin Finck
45*c2c66affSColin Finck #ifndef _STLP_INTERNAL_CSTDLIB
46*c2c66affSColin Finck # include <stl/_cstdlib.h>
47*c2c66affSColin Finck #endif
48*c2c66affSColin Finck
49*c2c66affSColin Finck #ifndef _STLP_INTERNAL_PAIR_H
50*c2c66affSColin Finck # include <stl/_pair.h>
51*c2c66affSColin Finck #endif
52*c2c66affSColin Finck
53*c2c66affSColin Finck #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
54*c2c66affSColin Finck # include <stl/_iterator_base.h>
55*c2c66affSColin Finck #endif
56*c2c66affSColin Finck
57*c2c66affSColin Finck #ifndef _STLP_TYPE_TRAITS_H
58*c2c66affSColin Finck # include <stl/type_traits.h>
59*c2c66affSColin Finck #endif
60*c2c66affSColin Finck
61*c2c66affSColin Finck _STLP_BEGIN_NAMESPACE
62*c2c66affSColin Finck
63*c2c66affSColin Finck #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
64*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
65*c2c66affSColin Finck template <class _Tp>
__swap_aux(_Tp & __a,_Tp & __b,const __true_type &)66*c2c66affSColin Finck inline void __swap_aux(_Tp& __a, _Tp& __b, const __true_type& /*SwapImplemented*/) {
67*c2c66affSColin Finck __a._M_swap_workaround(__b);
68*c2c66affSColin Finck }
69*c2c66affSColin Finck
70*c2c66affSColin Finck template <class _Tp>
__swap_aux(_Tp & __a,_Tp & __b,const __false_type &)71*c2c66affSColin Finck inline void __swap_aux(_Tp& __a, _Tp& __b, const __false_type& /*SwapImplemented*/) {
72*c2c66affSColin Finck _Tp __tmp = __a;
73*c2c66affSColin Finck __a = __b;
74*c2c66affSColin Finck __b = __tmp;
75*c2c66affSColin Finck }
76*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
77*c2c66affSColin Finck #endif
78*c2c66affSColin Finck
79*c2c66affSColin Finck // swap and iter_swap
80*c2c66affSColin Finck template <class _Tp>
swap(_Tp & __a,_Tp & __b)81*c2c66affSColin Finck inline void swap(_Tp& __a, _Tp& __b) {
82*c2c66affSColin Finck #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
83*c2c66affSColin Finck # if !defined(__BORLANDC__)
84*c2c66affSColin Finck typedef typename _SwapImplemented<_Tp>::_Ret _Implemented;
85*c2c66affSColin Finck # else
86*c2c66affSColin Finck enum { _Is = _SwapImplemented<_Tp>::_Is };
87*c2c66affSColin Finck typedef typename __bool2type<_Is>::_Ret _Implemented;
88*c2c66affSColin Finck # endif
89*c2c66affSColin Finck _STLP_PRIV __swap_aux(__a, __b, _Implemented());
90*c2c66affSColin Finck #else
91*c2c66affSColin Finck _Tp __tmp = __a;
92*c2c66affSColin Finck __a = __b;
93*c2c66affSColin Finck __b = __tmp;
94*c2c66affSColin Finck #endif
95*c2c66affSColin Finck }
96*c2c66affSColin Finck
97*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
98*c2c66affSColin Finck
99*c2c66affSColin Finck template <class _ForwardIter1, class _ForwardIter2, class _Value>
__iter_swap_aux_aux(_ForwardIter1 & __i1,_ForwardIter2 & __i2,_Value *)100*c2c66affSColin Finck inline void __iter_swap_aux_aux(_ForwardIter1& __i1, _ForwardIter2& __i2, _Value *) {
101*c2c66affSColin Finck _Value tmp = *__i1;
102*c2c66affSColin Finck *__i1 = *__i2;
103*c2c66affSColin Finck *__i2 = tmp;
104*c2c66affSColin Finck }
105*c2c66affSColin Finck
106*c2c66affSColin Finck template <class _ForwardIter1, class _ForwardIter2>
__iter_swap_aux(_ForwardIter1 & __i1,_ForwardIter2 & __i2,const __true_type &)107*c2c66affSColin Finck inline void __iter_swap_aux(_ForwardIter1& __i1, _ForwardIter2& __i2, const __true_type& /*OKToSwap*/) {
108*c2c66affSColin Finck /* namespace specification breaks access to the right swap template overload (at least for gcc) */
109*c2c66affSColin Finck /*_STLP_STD::*/ swap(*__i1, *__i2);
110*c2c66affSColin Finck }
111*c2c66affSColin Finck
112*c2c66affSColin Finck template <class _ForwardIter1, class _ForwardIter2>
__iter_swap_aux(_ForwardIter1 & __i1,_ForwardIter2 & __i2,const __false_type &)113*c2c66affSColin Finck inline void __iter_swap_aux(_ForwardIter1& __i1, _ForwardIter2& __i2, const __false_type& /*OKToSwap*/) {
114*c2c66affSColin Finck _STLP_PRIV __iter_swap_aux_aux( __i1, __i2, _STLP_VALUE_TYPE(__i1,_ForwardIter1) );
115*c2c66affSColin Finck }
116*c2c66affSColin Finck
117*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
118*c2c66affSColin Finck
119*c2c66affSColin Finck template <class _ForwardIter1, class _ForwardIter2>
iter_swap(_ForwardIter1 __i1,_ForwardIter2 __i2)120*c2c66affSColin Finck inline void iter_swap(_ForwardIter1 __i1, _ForwardIter2 __i2) {
121*c2c66affSColin Finck _STLP_PRIV __iter_swap_aux( __i1, __i2, _IsOKToSwap(_STLP_VALUE_TYPE(__i1, _ForwardIter1), _STLP_VALUE_TYPE(__i2, _ForwardIter2),
122*c2c66affSColin Finck _STLP_IS_REF_TYPE_REAL_REF(__i1, _ForwardIter1),
123*c2c66affSColin Finck _STLP_IS_REF_TYPE_REAL_REF(__i2, _ForwardIter2))._Answer());
124*c2c66affSColin Finck }
125*c2c66affSColin Finck
126*c2c66affSColin Finck //--------------------------------------------------
127*c2c66affSColin Finck // min and max
128*c2c66affSColin Finck
129*c2c66affSColin Finck #if !defined (__BORLANDC__) || defined (_STLP_USE_OWN_NAMESPACE)
130*c2c66affSColin Finck # if (defined (__BORLANDC__) && (__BORLANDC__ < 0x580)) && !defined (__STDC__)
131*c2c66affSColin Finck //In not ANSI mode Borland import min/max in global namespace which conflict
132*c2c66affSColin Finck //with STLport min/max when user does a 'using namespace std' in its code
133*c2c66affSColin Finck //(see test/unit/alg_test.cpp). To avoid this clash we simply import Borland min/max
134*c2c66affSColin Finck //in STLport namespace.
135*c2c66affSColin Finck using _STLP_VENDOR_STD::min;
136*c2c66affSColin Finck using _STLP_VENDOR_STD::max;
137*c2c66affSColin Finck # else
138*c2c66affSColin Finck template <class _Tp>
139*c2c66affSColin Finck inline const _Tp& (min)(const _Tp& __a, const _Tp& __b) { return __b < __a ? __b : __a; }
140*c2c66affSColin Finck template <class _Tp>
141*c2c66affSColin Finck inline const _Tp& (max)(const _Tp& __a, const _Tp& __b) { return __a < __b ? __b : __a; }
142*c2c66affSColin Finck # endif
143*c2c66affSColin Finck #endif
144*c2c66affSColin Finck
145*c2c66affSColin Finck # if defined (__BORLANDC__) && defined (_STLP_USE_OWN_NAMESPACE)
146*c2c66affSColin Finck inline unsigned long (min) (unsigned long __a, unsigned long __b) { return __b < __a ? __b : __a; }
147*c2c66affSColin Finck inline unsigned long (max) (unsigned long __a, unsigned long __b) { return __a < __b ? __b : __a; }
148*c2c66affSColin Finck # endif
149*c2c66affSColin Finck
150*c2c66affSColin Finck # if !defined (__BORLANDC__) || (__BORLANDC__ < 0x590)
151*c2c66affSColin Finck template <class _Tp, class _Compare>
152*c2c66affSColin Finck inline const _Tp& (min)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
153*c2c66affSColin Finck return __comp(__b, __a) ? __b : __a;
154*c2c66affSColin Finck }
155*c2c66affSColin Finck
156*c2c66affSColin Finck template <class _Tp, class _Compare>
157*c2c66affSColin Finck inline const _Tp& (max)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
158*c2c66affSColin Finck return __comp(__a, __b) ? __b : __a;
159*c2c66affSColin Finck }
160*c2c66affSColin Finck # else
161*c2c66affSColin Finck template <class _Tp, class _Compare>
_Tp(min)162*c2c66affSColin Finck inline const _Tp (min)(const _Tp __a, const _Tp __b, _Compare __comp) {
163*c2c66affSColin Finck return __comp(__b, __a) ? __b : __a;
164*c2c66affSColin Finck }
165*c2c66affSColin Finck
166*c2c66affSColin Finck template <class _Tp, class _Compare>
_Tp(max)167*c2c66affSColin Finck inline const _Tp (max)(const _Tp __a, const _Tp __b, _Compare __comp) {
168*c2c66affSColin Finck return __comp(__a, __b) ? __b : __a;
169*c2c66affSColin Finck }
170*c2c66affSColin Finck # endif
171*c2c66affSColin Finck
172*c2c66affSColin Finck //--------------------------------------------------
173*c2c66affSColin Finck // copy
174*c2c66affSColin Finck
175*c2c66affSColin Finck // All of these auxiliary functions serve two purposes. (1) Replace
176*c2c66affSColin Finck // calls to copy with memmove whenever possible. (Memmove, not memcpy,
177*c2c66affSColin Finck // because the input and output ranges are permitted to overlap.)
178*c2c66affSColin Finck // (2) If we're using random access iterators, then write the loop as
179*c2c66affSColin Finck // a for loop with an explicit count.
180*c2c66affSColin Finck
181*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
182*c2c66affSColin Finck
183*c2c66affSColin Finck template <class _InputIter, class _OutputIter, class _Distance>
__copy(_InputIter __first,_InputIter __last,_OutputIter __result,const input_iterator_tag &,_Distance *)184*c2c66affSColin Finck inline _OutputIter __copy(_InputIter __first, _InputIter __last,
185*c2c66affSColin Finck _OutputIter __result, const input_iterator_tag &, _Distance*) {
186*c2c66affSColin Finck for ( ; __first != __last; ++__result, ++__first)
187*c2c66affSColin Finck *__result = *__first;
188*c2c66affSColin Finck return __result;
189*c2c66affSColin Finck }
190*c2c66affSColin Finck
191*c2c66affSColin Finck #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
192*c2c66affSColin Finck template <class _InputIter, class _OutputIter, class _Distance>
__copy(_InputIter __first,_InputIter __last,_OutputIter __result,const forward_iterator_tag &,_Distance *)193*c2c66affSColin Finck inline _OutputIter __copy(_InputIter __first, _InputIter __last,
194*c2c66affSColin Finck _OutputIter __result, const forward_iterator_tag &, _Distance* ) {
195*c2c66affSColin Finck for ( ; __first != __last; ++__result, ++__first)
196*c2c66affSColin Finck *__result = *__first;
197*c2c66affSColin Finck return __result;
198*c2c66affSColin Finck }
199*c2c66affSColin Finck
200*c2c66affSColin Finck template <class _InputIter, class _OutputIter, class _Distance>
__copy(_InputIter __first,_InputIter __last,_OutputIter __result,const bidirectional_iterator_tag &,_Distance *)201*c2c66affSColin Finck inline _OutputIter __copy(_InputIter __first, _InputIter __last,
202*c2c66affSColin Finck _OutputIter __result, const bidirectional_iterator_tag &, _Distance* ) {
203*c2c66affSColin Finck for ( ; __first != __last; ++__result, ++__first)
204*c2c66affSColin Finck *__result = *__first;
205*c2c66affSColin Finck return __result;
206*c2c66affSColin Finck }
207*c2c66affSColin Finck #endif
208*c2c66affSColin Finck
209*c2c66affSColin Finck template <class _RandomAccessIter, class _OutputIter, class _Distance>
210*c2c66affSColin Finck inline _OutputIter
__copy(_RandomAccessIter __first,_RandomAccessIter __last,_OutputIter __result,const random_access_iterator_tag &,_Distance *)211*c2c66affSColin Finck __copy(_RandomAccessIter __first, _RandomAccessIter __last,
212*c2c66affSColin Finck _OutputIter __result, const random_access_iterator_tag &, _Distance*) {
213*c2c66affSColin Finck for (_Distance __n = __last - __first; __n > 0; --__n) {
214*c2c66affSColin Finck *__result = *__first;
215*c2c66affSColin Finck ++__first;
216*c2c66affSColin Finck ++__result;
217*c2c66affSColin Finck }
218*c2c66affSColin Finck return __result;
219*c2c66affSColin Finck }
220*c2c66affSColin Finck
221*c2c66affSColin Finck inline void*
__copy_trivial(const void * __first,const void * __last,void * __result)222*c2c66affSColin Finck __copy_trivial(const void* __first, const void* __last, void* __result) {
223*c2c66affSColin Finck size_t __n = (const char*)__last - (const char*)__first;
224*c2c66affSColin Finck return __n ? (void *)((char*)memmove(__result, __first, __n) + __n) : __result;
225*c2c66affSColin Finck }
226*c2c66affSColin Finck
227*c2c66affSColin Finck //--------------------------------------------------
228*c2c66affSColin Finck // copy_backward auxiliary functions
229*c2c66affSColin Finck
230*c2c66affSColin Finck template <class _BidirectionalIter1, class _BidirectionalIter2,
231*c2c66affSColin Finck class _Distance>
__copy_backward(_BidirectionalIter1 __first,_BidirectionalIter1 __last,_BidirectionalIter2 __result,const bidirectional_iterator_tag &,_Distance *)232*c2c66affSColin Finck inline _BidirectionalIter2 __copy_backward(_BidirectionalIter1 __first,
233*c2c66affSColin Finck _BidirectionalIter1 __last,
234*c2c66affSColin Finck _BidirectionalIter2 __result,
235*c2c66affSColin Finck const bidirectional_iterator_tag &,
236*c2c66affSColin Finck _Distance*) {
237*c2c66affSColin Finck while (__first != __last)
238*c2c66affSColin Finck *--__result = *--__last;
239*c2c66affSColin Finck return __result;
240*c2c66affSColin Finck }
241*c2c66affSColin Finck
242*c2c66affSColin Finck template <class _RandomAccessIter, class _BidirectionalIter, class _Distance>
__copy_backward(_RandomAccessIter __first,_RandomAccessIter __last,_BidirectionalIter __result,const random_access_iterator_tag &,_Distance *)243*c2c66affSColin Finck inline _BidirectionalIter __copy_backward(_RandomAccessIter __first,
244*c2c66affSColin Finck _RandomAccessIter __last,
245*c2c66affSColin Finck _BidirectionalIter __result,
246*c2c66affSColin Finck const random_access_iterator_tag &,
247*c2c66affSColin Finck _Distance*) {
248*c2c66affSColin Finck for (_Distance __n = __last - __first; __n > 0; --__n)
249*c2c66affSColin Finck *--__result = *--__last;
250*c2c66affSColin Finck return __result;
251*c2c66affSColin Finck }
252*c2c66affSColin Finck
253*c2c66affSColin Finck inline void*
__copy_trivial_backward(const void * __first,const void * __last,void * __result)254*c2c66affSColin Finck __copy_trivial_backward(const void* __first, const void* __last, void* __result) {
255*c2c66affSColin Finck const ptrdiff_t _Num = (const char*)__last - (const char*)__first;
256*c2c66affSColin Finck return (_Num > 0) ? memmove((char*)__result - _Num, __first, _Num) : __result ;
257*c2c66affSColin Finck }
258*c2c66affSColin Finck
259*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__copy_ptrs(_InputIter __first,_InputIter __last,_OutputIter __result,const __false_type &)260*c2c66affSColin Finck inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
261*c2c66affSColin Finck const __false_type& /*IsOKToMemCpy*/) {
262*c2c66affSColin Finck return _STLP_PRIV __copy(__first, __last, __result, random_access_iterator_tag(), (ptrdiff_t*)0);
263*c2c66affSColin Finck }
264*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__copy_ptrs(_InputIter __first,_InputIter __last,_OutputIter __result,const __true_type &)265*c2c66affSColin Finck inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
266*c2c66affSColin Finck const __true_type& /*IsOKToMemCpy*/) {
267*c2c66affSColin Finck // we know they all pointers, so this cast is OK
268*c2c66affSColin Finck // return (_OutputIter)__copy_trivial(&(*__first), &(*__last), &(*__result));
269*c2c66affSColin Finck return (_OutputIter)_STLP_PRIV __copy_trivial(__first, __last, __result);
270*c2c66affSColin Finck }
271*c2c66affSColin Finck
272*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__copy_aux(_InputIter __first,_InputIter __last,_OutputIter __result,const __true_type &)273*c2c66affSColin Finck inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
274*c2c66affSColin Finck const __true_type& /*BothPtrType*/) {
275*c2c66affSColin Finck return _STLP_PRIV __copy_ptrs(__first, __last, __result,
276*c2c66affSColin Finck _UseTrivialCopy(_STLP_VALUE_TYPE(__first, _InputIter),
277*c2c66affSColin Finck _STLP_VALUE_TYPE(__result, _OutputIter))._Answer());
278*c2c66affSColin Finck }
279*c2c66affSColin Finck
280*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__copy_aux(_InputIter __first,_InputIter __last,_OutputIter __result,const __false_type &)281*c2c66affSColin Finck inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
282*c2c66affSColin Finck const __false_type& /*BothPtrType*/) {
283*c2c66affSColin Finck return _STLP_PRIV __copy(__first, __last, __result,
284*c2c66affSColin Finck _STLP_ITERATOR_CATEGORY(__first, _InputIter),
285*c2c66affSColin Finck _STLP_DISTANCE_TYPE(__first, _InputIter));
286*c2c66affSColin Finck }
287*c2c66affSColin Finck
288*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
289*c2c66affSColin Finck
290*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
copy(_InputIter __first,_InputIter __last,_OutputIter __result)291*c2c66affSColin Finck inline _OutputIter copy(_InputIter __first, _InputIter __last, _OutputIter __result) {
292*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
293*c2c66affSColin Finck return _STLP_PRIV __copy_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter>::_Answer());
294*c2c66affSColin Finck }
295*c2c66affSColin Finck
296*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
297*c2c66affSColin Finck
298*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__copy_backward_ptrs(_InputIter __first,_InputIter __last,_OutputIter __result,const __false_type &)299*c2c66affSColin Finck inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last,
300*c2c66affSColin Finck _OutputIter __result, const __false_type& /*TrivialAssignment*/) {
301*c2c66affSColin Finck return _STLP_PRIV __copy_backward(__first, __last, __result,
302*c2c66affSColin Finck _STLP_ITERATOR_CATEGORY(__first, _InputIter),
303*c2c66affSColin Finck _STLP_DISTANCE_TYPE(__first, _InputIter));
304*c2c66affSColin Finck }
305*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__copy_backward_ptrs(_InputIter __first,_InputIter __last,_OutputIter __result,const __true_type &)306*c2c66affSColin Finck inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last,
307*c2c66affSColin Finck _OutputIter __result, const __true_type& /*TrivialAssignment*/) {
308*c2c66affSColin Finck return (_OutputIter)_STLP_PRIV __copy_trivial_backward(__first, __last, __result);
309*c2c66affSColin Finck }
310*c2c66affSColin Finck
311*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__copy_backward_aux(_InputIter __first,_InputIter __last,_OutputIter __result,const __false_type &)312*c2c66affSColin Finck inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
313*c2c66affSColin Finck return _STLP_PRIV __copy_backward(__first, __last, __result,
314*c2c66affSColin Finck _STLP_ITERATOR_CATEGORY(__first,_InputIter),
315*c2c66affSColin Finck _STLP_DISTANCE_TYPE(__first, _InputIter));
316*c2c66affSColin Finck }
317*c2c66affSColin Finck
318*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__copy_backward_aux(_InputIter __first,_InputIter __last,_OutputIter __result,const __true_type &)319*c2c66affSColin Finck inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
320*c2c66affSColin Finck return _STLP_PRIV __copy_backward_ptrs(__first, __last, __result,
321*c2c66affSColin Finck _UseTrivialCopy(_STLP_VALUE_TYPE(__first, _InputIter),
322*c2c66affSColin Finck _STLP_VALUE_TYPE(__result, _OutputIter))._Answer());
323*c2c66affSColin Finck }
324*c2c66affSColin Finck
325*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
326*c2c66affSColin Finck
327*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
copy_backward(_InputIter __first,_InputIter __last,_OutputIter __result)328*c2c66affSColin Finck inline _OutputIter copy_backward(_InputIter __first, _InputIter __last, _OutputIter __result) {
329*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
330*c2c66affSColin Finck return _STLP_PRIV __copy_backward_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter>::_Answer() );
331*c2c66affSColin Finck }
332*c2c66affSColin Finck
333*c2c66affSColin Finck #if !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS)
334*c2c66affSColin Finck # define _STLP_DECLARE_COPY_TRIVIAL(_Tp) \
335*c2c66affSColin Finck inline _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) \
336*c2c66affSColin Finck { return (_Tp*)_STLP_PRIV __copy_trivial(__first, __last, __result); } \
337*c2c66affSColin Finck inline _Tp* copy_backward(const _Tp* __first, const _Tp* __last, _Tp* __result) \
338*c2c66affSColin Finck { return (_Tp*)_STLP_PRIV __copy_trivial_backward(__first, __last, __result); }
339*c2c66affSColin Finck
340*c2c66affSColin Finck # if !defined (_STLP_NO_BOOL)
341*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(bool)
342*c2c66affSColin Finck # endif
_STLP_DECLARE_COPY_TRIVIAL(char)343*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(char)
344*c2c66affSColin Finck # if !defined (_STLP_NO_SIGNED_BUILTINS)
345*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(signed char)
346*c2c66affSColin Finck # endif
347*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(unsigned char)
348*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(short)
349*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(unsigned short)
350*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(int)
351*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(unsigned int)
352*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(long)
353*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(unsigned long)
354*c2c66affSColin Finck # if !defined(_STLP_NO_WCHAR_T) && !defined (_STLP_WCHAR_T_IS_USHORT)
355*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(wchar_t)
356*c2c66affSColin Finck # endif
357*c2c66affSColin Finck # if defined (_STLP_LONG_LONG)
358*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(_STLP_LONG_LONG)
359*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(unsigned _STLP_LONG_LONG)
360*c2c66affSColin Finck # endif
361*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(float)
362*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(double)
363*c2c66affSColin Finck # if !defined (_STLP_NO_LONG_DOUBLE)
364*c2c66affSColin Finck _STLP_DECLARE_COPY_TRIVIAL(long double)
365*c2c66affSColin Finck # endif
366*c2c66affSColin Finck # undef _STLP_DECLARE_COPY_TRIVIAL
367*c2c66affSColin Finck #endif
368*c2c66affSColin Finck
369*c2c66affSColin Finck //--------------------------------------------------
370*c2c66affSColin Finck // copy_n (not part of the C++ standard)
371*c2c66affSColin Finck
372*c2c66affSColin Finck #if !defined (_STLP_NO_EXTENSIONS)
373*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
374*c2c66affSColin Finck
375*c2c66affSColin Finck template <class _InputIter, class _Size, class _OutputIter>
376*c2c66affSColin Finck _STLP_INLINE_LOOP _STLP_STD::pair<_InputIter, _OutputIter>
377*c2c66affSColin Finck __copy_n(_InputIter __first, _Size __count, _OutputIter __result,
378*c2c66affSColin Finck const input_iterator_tag &) {
379*c2c66affSColin Finck for ( ; __count > 0; --__count) {
380*c2c66affSColin Finck *__result = *__first;
381*c2c66affSColin Finck ++__first;
382*c2c66affSColin Finck ++__result;
383*c2c66affSColin Finck }
384*c2c66affSColin Finck return _STLP_STD::pair<_InputIter, _OutputIter>(__first, __result);
385*c2c66affSColin Finck }
386*c2c66affSColin Finck
387*c2c66affSColin Finck template <class _RAIter, class _Size, class _OutputIter>
388*c2c66affSColin Finck inline _STLP_STD::pair<_RAIter, _OutputIter>
__copy_n(_RAIter __first,_Size __count,_OutputIter __result,const random_access_iterator_tag &)389*c2c66affSColin Finck __copy_n(_RAIter __first, _Size __count, _OutputIter __result,
390*c2c66affSColin Finck const random_access_iterator_tag &) {
391*c2c66affSColin Finck _RAIter __last = __first + __count;
392*c2c66affSColin Finck return _STLP_STD::pair<_RAIter, _OutputIter>(__last, _STLP_STD::copy(__first, __last, __result));
393*c2c66affSColin Finck }
394*c2c66affSColin Finck
395*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
396*c2c66affSColin Finck
397*c2c66affSColin Finck template <class _InputIter, class _Size, class _OutputIter>
398*c2c66affSColin Finck inline pair<_InputIter, _OutputIter>
copy_n(_InputIter __first,_Size __count,_OutputIter __result)399*c2c66affSColin Finck copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
400*c2c66affSColin Finck _STLP_FIX_LITERAL_BUG(__first)
401*c2c66affSColin Finck return _STLP_PRIV __copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
402*c2c66affSColin Finck }
403*c2c66affSColin Finck #endif
404*c2c66affSColin Finck
405*c2c66affSColin Finck //--------------------------------------------------
406*c2c66affSColin Finck // fill and fill_n
407*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
408*c2c66affSColin Finck
409*c2c66affSColin Finck template <class _ForwardIter, class _Tp>
410*c2c66affSColin Finck _STLP_INLINE_LOOP
__fill_fwd(_ForwardIter __first,_ForwardIter __last,const _Tp & __val)411*c2c66affSColin Finck void __fill_fwd(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
412*c2c66affSColin Finck for ( ; __first != __last; ++__first)
413*c2c66affSColin Finck *__first = __val;
414*c2c66affSColin Finck }
415*c2c66affSColin Finck
416*c2c66affSColin Finck template <class _ForwardIter, class _Tp, class _Distance>
__fill(_ForwardIter __first,_ForwardIter __last,const _Tp & __val,const input_iterator_tag &,_Distance *)417*c2c66affSColin Finck inline void __fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
418*c2c66affSColin Finck const input_iterator_tag &, _Distance*) {
419*c2c66affSColin Finck _STLP_PRIV __fill_fwd(__first, __last, __val);
420*c2c66affSColin Finck }
421*c2c66affSColin Finck
422*c2c66affSColin Finck #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
423*c2c66affSColin Finck template <class _ForwardIter, class _Tp, class _Distance>
424*c2c66affSColin Finck _STLP_INLINE_LOOP
__fill(_ForwardIter __first,_ForwardIter __last,const _Tp & __val,const forward_iterator_tag &,_Distance *)425*c2c66affSColin Finck void __fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
426*c2c66affSColin Finck const forward_iterator_tag &, _Distance*) {
427*c2c66affSColin Finck _STLP_PRIV __fill_fwd(__first, __last, __val);
428*c2c66affSColin Finck }
429*c2c66affSColin Finck
430*c2c66affSColin Finck template <class _ForwardIter, class _Tp, class _Distance>
431*c2c66affSColin Finck _STLP_INLINE_LOOP
__fill(_ForwardIter __first,_ForwardIter __last,const _Tp & __val,const bidirectional_iterator_tag &,_Distance *)432*c2c66affSColin Finck void __fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
433*c2c66affSColin Finck const bidirectional_iterator_tag &, _Distance*) {
434*c2c66affSColin Finck _STLP_PRIV __fill_fwd(__first, __last, __val);
435*c2c66affSColin Finck }
436*c2c66affSColin Finck #endif
437*c2c66affSColin Finck
438*c2c66affSColin Finck template <class _RandomAccessIter, class _Tp, class _Distance>
439*c2c66affSColin Finck _STLP_INLINE_LOOP
__fill(_RandomAccessIter __first,_RandomAccessIter __last,const _Tp & __val,const random_access_iterator_tag &,_Distance *)440*c2c66affSColin Finck void __fill(_RandomAccessIter __first, _RandomAccessIter __last, const _Tp& __val,
441*c2c66affSColin Finck const random_access_iterator_tag &, _Distance*) {
442*c2c66affSColin Finck for (_Distance __n = __last - __first ; __n > 0; ++__first, --__n)
443*c2c66affSColin Finck *__first = __val;
444*c2c66affSColin Finck }
445*c2c66affSColin Finck
446*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
447*c2c66affSColin Finck
448*c2c66affSColin Finck template <class _ForwardIter, class _Tp>
fill(_ForwardIter __first,_ForwardIter __last,const _Tp & __val)449*c2c66affSColin Finck inline void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
450*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
451*c2c66affSColin Finck _STLP_PRIV __fill(__first, __last, __val,
452*c2c66affSColin Finck _STLP_ITERATOR_CATEGORY(__first, _ForwardIter),
453*c2c66affSColin Finck _STLP_DISTANCE_TYPE(__first, _ForwardIter));
454*c2c66affSColin Finck }
455*c2c66affSColin Finck
456*c2c66affSColin Finck // Specialization: for one-byte types we can use memset.
fill(unsigned char * __first,unsigned char * __last,const unsigned char & __val)457*c2c66affSColin Finck inline void fill(unsigned char* __first, unsigned char* __last,
458*c2c66affSColin Finck const unsigned char& __val) {
459*c2c66affSColin Finck unsigned char __tmp = __val;
460*c2c66affSColin Finck memset(__first, __tmp, __last - __first);
461*c2c66affSColin Finck }
462*c2c66affSColin Finck #if !defined (_STLP_NO_SIGNED_BUILTINS)
fill(signed char * __first,signed char * __last,const signed char & __val)463*c2c66affSColin Finck inline void fill(signed char* __first, signed char* __last,
464*c2c66affSColin Finck const signed char& __val) {
465*c2c66affSColin Finck signed char __tmp = __val;
466*c2c66affSColin Finck memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
467*c2c66affSColin Finck }
468*c2c66affSColin Finck #endif
fill(char * __first,char * __last,const char & __val)469*c2c66affSColin Finck inline void fill(char* __first, char* __last, const char& __val) {
470*c2c66affSColin Finck char __tmp = __val;
471*c2c66affSColin Finck memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
472*c2c66affSColin Finck }
473*c2c66affSColin Finck
474*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
475*c2c66affSColin Finck
476*c2c66affSColin Finck template <class _OutputIter, class _Size, class _Tp>
477*c2c66affSColin Finck _STLP_INLINE_LOOP
__fill_n(_OutputIter __first,_Size __n,const _Tp & __val)478*c2c66affSColin Finck _OutputIter __fill_n(_OutputIter __first, _Size __n, const _Tp& __val) {
479*c2c66affSColin Finck _STLP_FIX_LITERAL_BUG(__first)
480*c2c66affSColin Finck for ( ; __n > 0; --__n, ++__first)
481*c2c66affSColin Finck *__first = __val;
482*c2c66affSColin Finck return __first;
483*c2c66affSColin Finck }
484*c2c66affSColin Finck
485*c2c66affSColin Finck #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
486*c2c66affSColin Finck template <class _Size>
__fill_n(unsigned char * __first,_Size __n,const unsigned char & __val)487*c2c66affSColin Finck inline unsigned char* __fill_n(unsigned char* __first, _Size __n,
488*c2c66affSColin Finck const unsigned char& __val) {
489*c2c66affSColin Finck _STLP_STD::fill(__first, __first + __n, __val);
490*c2c66affSColin Finck return __first + __n;
491*c2c66affSColin Finck }
492*c2c66affSColin Finck #if !defined (_STLP_NO_SIGNED_BUILTINS)
493*c2c66affSColin Finck template <class _Size>
__fill_n(signed char * __first,_Size __n,const signed char & __val)494*c2c66affSColin Finck inline signed char* __fill_n(signed char* __first, _Size __n,
495*c2c66affSColin Finck const signed char& __val) {
496*c2c66affSColin Finck _STLP_STD::fill(__first, __first + __n, __val);
497*c2c66affSColin Finck return __first + __n;
498*c2c66affSColin Finck }
499*c2c66affSColin Finck #endif
500*c2c66affSColin Finck template <class _Size>
__fill_n(char * __first,_Size __n,const char & __val)501*c2c66affSColin Finck inline char* __fill_n(char* __first, _Size __n,
502*c2c66affSColin Finck const char& __val) {
503*c2c66affSColin Finck _STLP_STD::fill(__first, __first + __n, __val);
504*c2c66affSColin Finck return __first + __n;
505*c2c66affSColin Finck }
506*c2c66affSColin Finck #endif
507*c2c66affSColin Finck
508*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
509*c2c66affSColin Finck
510*c2c66affSColin Finck template <class _OutputIter, class _Size, class _Tp>
fill_n(_OutputIter __first,_Size __n,const _Tp & __val)511*c2c66affSColin Finck inline void fill_n(_OutputIter __first, _Size __n, const _Tp& __val) {
512*c2c66affSColin Finck _STLP_FIX_LITERAL_BUG(__first)
513*c2c66affSColin Finck _STLP_PRIV __fill_n(__first, __n, __val);
514*c2c66affSColin Finck }
515*c2c66affSColin Finck
516*c2c66affSColin Finck
517*c2c66affSColin Finck //--------------------------------------------------
518*c2c66affSColin Finck // equal and mismatch
519*c2c66affSColin Finck
520*c2c66affSColin Finck template <class _InputIter1, class _InputIter2>
521*c2c66affSColin Finck _STLP_INLINE_LOOP
mismatch(_InputIter1 __first1,_InputIter1 __last1,_InputIter2 __first2)522*c2c66affSColin Finck _STLP_STD::pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
523*c2c66affSColin Finck _InputIter1 __last1,
524*c2c66affSColin Finck _InputIter2 __first2) {
525*c2c66affSColin Finck _STLP_FIX_LITERAL_BUG(__first2)
526*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
527*c2c66affSColin Finck while (__first1 != __last1 && *__first1 == *__first2) {
528*c2c66affSColin Finck ++__first1;
529*c2c66affSColin Finck ++__first2;
530*c2c66affSColin Finck }
531*c2c66affSColin Finck return _STLP_STD::pair<_InputIter1, _InputIter2>(__first1, __first2);
532*c2c66affSColin Finck }
533*c2c66affSColin Finck
534*c2c66affSColin Finck template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
535*c2c66affSColin Finck _STLP_INLINE_LOOP
mismatch(_InputIter1 __first1,_InputIter1 __last1,_InputIter2 __first2,_BinaryPredicate __binary_pred)536*c2c66affSColin Finck _STLP_STD::pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
537*c2c66affSColin Finck _InputIter1 __last1,
538*c2c66affSColin Finck _InputIter2 __first2,
539*c2c66affSColin Finck _BinaryPredicate __binary_pred) {
540*c2c66affSColin Finck _STLP_FIX_LITERAL_BUG(__first2)
541*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
542*c2c66affSColin Finck while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) {
543*c2c66affSColin Finck ++__first1;
544*c2c66affSColin Finck ++__first2;
545*c2c66affSColin Finck }
546*c2c66affSColin Finck return _STLP_STD::pair<_InputIter1, _InputIter2>(__first1, __first2);
547*c2c66affSColin Finck }
548*c2c66affSColin Finck
549*c2c66affSColin Finck template <class _InputIter1, class _InputIter2>
550*c2c66affSColin Finck _STLP_INLINE_LOOP
equal(_InputIter1 __first1,_InputIter1 __last1,_InputIter2 __first2)551*c2c66affSColin Finck bool equal(_InputIter1 __first1, _InputIter1 __last1,
552*c2c66affSColin Finck _InputIter2 __first2) {
553*c2c66affSColin Finck _STLP_FIX_LITERAL_BUG(__first1) _STLP_FIX_LITERAL_BUG(__last1) _STLP_FIX_LITERAL_BUG(__first2)
554*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
555*c2c66affSColin Finck for ( ; __first1 != __last1; ++__first1, ++__first2)
556*c2c66affSColin Finck if (!(*__first1 == *__first2))
557*c2c66affSColin Finck return false;
558*c2c66affSColin Finck return true;
559*c2c66affSColin Finck }
560*c2c66affSColin Finck
561*c2c66affSColin Finck template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
562*c2c66affSColin Finck _STLP_INLINE_LOOP
equal(_InputIter1 __first1,_InputIter1 __last1,_InputIter2 __first2,_BinaryPredicate __binary_pred)563*c2c66affSColin Finck bool equal(_InputIter1 __first1, _InputIter1 __last1,
564*c2c66affSColin Finck _InputIter2 __first2, _BinaryPredicate __binary_pred) {
565*c2c66affSColin Finck _STLP_FIX_LITERAL_BUG(__first2)
566*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
567*c2c66affSColin Finck for ( ; __first1 != __last1; ++__first1, ++__first2)
568*c2c66affSColin Finck if (!__binary_pred(*__first1, *__first2))
569*c2c66affSColin Finck return false;
570*c2c66affSColin Finck return true;
571*c2c66affSColin Finck }
572*c2c66affSColin Finck
573*c2c66affSColin Finck //--------------------------------------------------
574*c2c66affSColin Finck // lexicographical_compare and lexicographical_compare_3way.
575*c2c66affSColin Finck // (the latter is not part of the C++ standard.)
576*c2c66affSColin Finck
577*c2c66affSColin Finck template <class _InputIter1, class _InputIter2>
578*c2c66affSColin Finck bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
579*c2c66affSColin Finck _InputIter2 __first2, _InputIter2 __last2);
580*c2c66affSColin Finck
581*c2c66affSColin Finck template <class _InputIter1, class _InputIter2, class _Compare>
582*c2c66affSColin Finck bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
583*c2c66affSColin Finck _InputIter2 __first2, _InputIter2 __last2,
584*c2c66affSColin Finck _Compare __comp);
585*c2c66affSColin Finck
586*c2c66affSColin Finck inline bool
lexicographical_compare(const unsigned char * __first1,const unsigned char * __last1,const unsigned char * __first2,const unsigned char * __last2)587*c2c66affSColin Finck lexicographical_compare(const unsigned char* __first1,
588*c2c66affSColin Finck const unsigned char* __last1,
589*c2c66affSColin Finck const unsigned char* __first2,
590*c2c66affSColin Finck const unsigned char* __last2) {
591*c2c66affSColin Finck const size_t __len1 = __last1 - __first1;
592*c2c66affSColin Finck const size_t __len2 = __last2 - __first2;
593*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
594*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
595*c2c66affSColin Finck
596*c2c66affSColin Finck const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
597*c2c66affSColin Finck return __result != 0 ? (__result < 0) : (__len1 < __len2);
598*c2c66affSColin Finck }
599*c2c66affSColin Finck
600*c2c66affSColin Finck
601*c2c66affSColin Finck #if !(CHAR_MAX == SCHAR_MAX)
lexicographical_compare(const char * __first1,const char * __last1,const char * __first2,const char * __last2)602*c2c66affSColin Finck inline bool lexicographical_compare(const char* __first1, const char* __last1,
603*c2c66affSColin Finck const char* __first2, const char* __last2) {
604*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
605*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
606*c2c66affSColin Finck
607*c2c66affSColin Finck return lexicographical_compare((const unsigned char*) __first1,
608*c2c66affSColin Finck (const unsigned char*) __last1,
609*c2c66affSColin Finck (const unsigned char*) __first2,
610*c2c66affSColin Finck (const unsigned char*) __last2);
611*c2c66affSColin Finck }
612*c2c66affSColin Finck #endif /* CHAR_MAX == SCHAR_MAX */
613*c2c66affSColin Finck
614*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
615*c2c66affSColin Finck
616*c2c66affSColin Finck template <class _InputIter1, class _InputIter2>
617*c2c66affSColin Finck int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
618*c2c66affSColin Finck _InputIter2 __first2, _InputIter2 __last2);
619*c2c66affSColin Finck
620*c2c66affSColin Finck inline int
__lexicographical_compare_3way(const unsigned char * __first1,const unsigned char * __last1,const unsigned char * __first2,const unsigned char * __last2)621*c2c66affSColin Finck __lexicographical_compare_3way(const unsigned char* __first1,
622*c2c66affSColin Finck const unsigned char* __last1,
623*c2c66affSColin Finck const unsigned char* __first2,
624*c2c66affSColin Finck const unsigned char* __last2) {
625*c2c66affSColin Finck const ptrdiff_t __len1 = __last1 - __first1;
626*c2c66affSColin Finck const ptrdiff_t __len2 = __last2 - __first2;
627*c2c66affSColin Finck const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
628*c2c66affSColin Finck return __result != 0 ? __result
629*c2c66affSColin Finck : (__len1 == __len2 ? 0 : (__len1 < __len2 ? -1 : 1));
630*c2c66affSColin Finck }
631*c2c66affSColin Finck
632*c2c66affSColin Finck
633*c2c66affSColin Finck #if !(CHAR_MAX == SCHAR_MAX)
634*c2c66affSColin Finck inline int
__lexicographical_compare_3way(const char * __first1,const char * __last1,const char * __first2,const char * __last2)635*c2c66affSColin Finck __lexicographical_compare_3way(const char* __first1, const char* __last1,
636*c2c66affSColin Finck const char* __first2, const char* __last2) {
637*c2c66affSColin Finck return __lexicographical_compare_3way((const unsigned char*) __first1,
638*c2c66affSColin Finck (const unsigned char*) __last1,
639*c2c66affSColin Finck (const unsigned char*) __first2,
640*c2c66affSColin Finck (const unsigned char*) __last2);
641*c2c66affSColin Finck }
642*c2c66affSColin Finck #endif
643*c2c66affSColin Finck
644*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
645*c2c66affSColin Finck
646*c2c66affSColin Finck #if !defined (_STLP_NO_EXTENSIONS)
647*c2c66affSColin Finck template <class _InputIter1, class _InputIter2>
648*c2c66affSColin Finck int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
649*c2c66affSColin Finck _InputIter2 __first2, _InputIter2 __last2);
650*c2c66affSColin Finck
651*c2c66affSColin Finck #endif
652*c2c66affSColin Finck
653*c2c66affSColin Finck // count
654*c2c66affSColin Finck template <class _InputIter, class _Tp>
_STLP_DIFFERENCE_TYPE(_InputIter)655*c2c66affSColin Finck _STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
656*c2c66affSColin Finck count(_InputIter __first, _InputIter __last, const _Tp& __val) {
657*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
658*c2c66affSColin Finck _STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
659*c2c66affSColin Finck for ( ; __first != __last; ++__first)
660*c2c66affSColin Finck if (*__first == __val)
661*c2c66affSColin Finck ++__n;
662*c2c66affSColin Finck return __n;
663*c2c66affSColin Finck }
664*c2c66affSColin Finck
665*c2c66affSColin Finck // find and find_if. Note find may be expressed in terms of find_if if appropriate binder was available.
666*c2c66affSColin Finck template <class _InputIter, class _Tp>
667*c2c66affSColin Finck _InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val);
668*c2c66affSColin Finck
669*c2c66affSColin Finck template <class _InputIter, class _Predicate>
670*c2c66affSColin Finck _InputIter find_if(_InputIter __first, _InputIter __last, _Predicate __pred);
671*c2c66affSColin Finck
672*c2c66affSColin Finck // search.
673*c2c66affSColin Finck template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
674*c2c66affSColin Finck _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
675*c2c66affSColin Finck _ForwardIter2 __first2, _ForwardIter2 __last2, _BinaryPred __predicate);
676*c2c66affSColin Finck
677*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
678*c2c66affSColin Finck
679*c2c66affSColin Finck // find_first_of
680*c2c66affSColin Finck template <class _InputIter, class _ForwardIter>
681*c2c66affSColin Finck _InputIter __find_first_of(_InputIter __first1, _InputIter __last1,
682*c2c66affSColin Finck _ForwardIter __first2, _ForwardIter __last2);
683*c2c66affSColin Finck
684*c2c66affSColin Finck template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
685*c2c66affSColin Finck _InputIter __find_first_of(_InputIter __first1, _InputIter __last1,
686*c2c66affSColin Finck _ForwardIter __first2, _ForwardIter __last2,
687*c2c66affSColin Finck _BinaryPredicate __comp);
688*c2c66affSColin Finck
689*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
690*c2c66affSColin Finck
691*c2c66affSColin Finck template <class _ForwardIter1, class _ForwardIter2,
692*c2c66affSColin Finck class _BinaryPredicate>
693*c2c66affSColin Finck _ForwardIter1
694*c2c66affSColin Finck find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
695*c2c66affSColin Finck _ForwardIter2 __first2, _ForwardIter2 __last2,
696*c2c66affSColin Finck _BinaryPredicate __comp);
697*c2c66affSColin Finck
698*c2c66affSColin Finck // replace
699*c2c66affSColin Finck template <class _ForwardIter, class _Tp>
700*c2c66affSColin Finck _STLP_INLINE_LOOP void
replace(_ForwardIter __first,_ForwardIter __last,const _Tp & __old_value,const _Tp & __new_value)701*c2c66affSColin Finck replace(_ForwardIter __first, _ForwardIter __last,
702*c2c66affSColin Finck const _Tp& __old_value, const _Tp& __new_value) {
703*c2c66affSColin Finck _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
704*c2c66affSColin Finck for ( ; __first != __last; ++__first)
705*c2c66affSColin Finck if (*__first == __old_value)
706*c2c66affSColin Finck *__first = __new_value;
707*c2c66affSColin Finck }
708*c2c66affSColin Finck
709*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
710*c2c66affSColin Finck
711*c2c66affSColin Finck template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
712*c2c66affSColin Finck _ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
713*c2c66affSColin Finck const _Tp& __val, _Compare1 __comp1, _Compare2 __comp2, _Distance*);
714*c2c66affSColin Finck
715*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
716*c2c66affSColin Finck
717*c2c66affSColin Finck _STLP_END_NAMESPACE
718*c2c66affSColin Finck
719*c2c66affSColin Finck #if !defined (_STLP_LINK_TIME_INSTANTIATION)
720*c2c66affSColin Finck # include <stl/_algobase.c>
721*c2c66affSColin Finck #endif
722*c2c66affSColin Finck
723*c2c66affSColin Finck #endif /* _STLP_INTERNAL_ALGOBASE_H */
724*c2c66affSColin Finck
725*c2c66affSColin Finck // Local Variables:
726*c2c66affSColin Finck // mode:C++
727*c2c66affSColin Finck // End:
728*c2c66affSColin Finck
729