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_UNINITIALIZED_H
31*c2c66affSColin Finck #define _STLP_INTERNAL_UNINITIALIZED_H
32*c2c66affSColin Finck
33*c2c66affSColin Finck #ifndef _STLP_INTERNAL_CSTRING
34*c2c66affSColin Finck # include <stl/_cstring.h>
35*c2c66affSColin Finck #endif
36*c2c66affSColin Finck
37*c2c66affSColin Finck #ifndef _STLP_INTERNAL_ALGOBASE_H
38*c2c66affSColin Finck # include <stl/_algobase.h>
39*c2c66affSColin Finck #endif
40*c2c66affSColin Finck
41*c2c66affSColin Finck #ifndef _STLP_INTERNAL_CONSTRUCT_H
42*c2c66affSColin Finck # include <stl/_construct.h>
43*c2c66affSColin Finck #endif
44*c2c66affSColin Finck
45*c2c66affSColin Finck _STLP_BEGIN_NAMESPACE
46*c2c66affSColin Finck
47*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
48*c2c66affSColin Finck
49*c2c66affSColin Finck // uninitialized_copy
50*c2c66affSColin Finck
51*c2c66affSColin Finck template <class _InputIter, class _OutputIter, class _Distance>
__ucopy(_InputIter __first,_InputIter __last,_OutputIter __result,_Distance *)52*c2c66affSColin Finck inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
53*c2c66affSColin Finck _OutputIter __result, _Distance*) {
54*c2c66affSColin Finck _OutputIter __cur = __result;
55*c2c66affSColin Finck _STLP_TRY {
56*c2c66affSColin Finck for ( ; __first != __last; ++__first, ++__cur)
57*c2c66affSColin Finck _Param_Construct(&*__cur, *__first);
58*c2c66affSColin Finck return __cur;
59*c2c66affSColin Finck }
60*c2c66affSColin Finck _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __cur))
61*c2c66affSColin Finck _STLP_RET_AFTER_THROW(__cur)
62*c2c66affSColin Finck }
63*c2c66affSColin Finck
64*c2c66affSColin Finck template <class _InputIter, class _OutputIter, class _Distance>
__ucopy(_InputIter __first,_InputIter __last,_OutputIter __result,const input_iterator_tag &,_Distance * __d)65*c2c66affSColin Finck inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
66*c2c66affSColin Finck _OutputIter __result, const input_iterator_tag &, _Distance* __d)
67*c2c66affSColin Finck { return __ucopy(__first, __last, __result, __d); }
68*c2c66affSColin Finck
69*c2c66affSColin Finck #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
70*c2c66affSColin Finck template <class _InputIter, class _OutputIter, class _Distance>
__ucopy(_InputIter __first,_InputIter __last,_OutputIter __result,const forward_iterator_tag &,_Distance * __d)71*c2c66affSColin Finck inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
72*c2c66affSColin Finck _OutputIter __result, const forward_iterator_tag &, _Distance* __d)
73*c2c66affSColin Finck { return __ucopy(__first, __last, __result, __d); }
74*c2c66affSColin Finck
75*c2c66affSColin Finck template <class _InputIter, class _OutputIter, class _Distance>
__ucopy(_InputIter __first,_InputIter __last,_OutputIter __result,const bidirectional_iterator_tag &,_Distance * __d)76*c2c66affSColin Finck inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
77*c2c66affSColin Finck _OutputIter __result, const bidirectional_iterator_tag &, _Distance* __d)
78*c2c66affSColin Finck { return __ucopy(__first, __last, __result, __d); }
79*c2c66affSColin Finck #endif
80*c2c66affSColin Finck
81*c2c66affSColin Finck template <class _RandomAccessIter, class _OutputIter, class _Distance>
__ucopy(_RandomAccessIter __first,_RandomAccessIter __last,_OutputIter __result,const random_access_iterator_tag &,_Distance *)82*c2c66affSColin Finck inline _OutputIter __ucopy(_RandomAccessIter __first, _RandomAccessIter __last,
83*c2c66affSColin Finck _OutputIter __result, const random_access_iterator_tag &, _Distance*) {
84*c2c66affSColin Finck _OutputIter __cur = __result;
85*c2c66affSColin Finck _STLP_TRY {
86*c2c66affSColin Finck for (_Distance __n = __last - __first; __n > 0; --__n) {
87*c2c66affSColin Finck _Param_Construct(&*__cur, *__first);
88*c2c66affSColin Finck ++__first;
89*c2c66affSColin Finck ++__cur;
90*c2c66affSColin Finck }
91*c2c66affSColin Finck return __cur;
92*c2c66affSColin Finck }
93*c2c66affSColin Finck _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __cur))
94*c2c66affSColin Finck _STLP_RET_AFTER_THROW(__cur)
95*c2c66affSColin Finck }
96*c2c66affSColin Finck
97*c2c66affSColin Finck //Used internaly
98*c2c66affSColin Finck template <class _RandomAccessIter, class _OutputIter>
__ucopy(_RandomAccessIter __first,_RandomAccessIter __last,_OutputIter __result)99*c2c66affSColin Finck inline _OutputIter __ucopy(_RandomAccessIter __first, _RandomAccessIter __last, _OutputIter __result)
100*c2c66affSColin Finck { return __ucopy(__first, __last, __result, random_access_iterator_tag(), (ptrdiff_t*)0); }
101*c2c66affSColin Finck
102*c2c66affSColin Finck inline void*
__ucopy_trivial(const void * __first,const void * __last,void * __result)103*c2c66affSColin Finck __ucopy_trivial(const void* __first, const void* __last, void* __result) {
104*c2c66affSColin Finck //dums: this version can use memcpy (__copy_trivial can't)
105*c2c66affSColin Finck return (__last == __first) ? __result :
106*c2c66affSColin Finck ((char*)memcpy(__result, __first, ((const char*)__last - (const char*)__first))) +
107*c2c66affSColin Finck ((const char*)__last - (const char*)__first);
108*c2c66affSColin Finck }
109*c2c66affSColin Finck
110*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__ucopy_ptrs(_InputIter __first,_InputIter __last,_OutputIter __result,const __false_type &)111*c2c66affSColin Finck inline _OutputIter __ucopy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
112*c2c66affSColin Finck const __false_type& /*TrivialUCopy*/)
113*c2c66affSColin Finck { return __ucopy(__first, __last, __result, random_access_iterator_tag(), (ptrdiff_t*)0); }
114*c2c66affSColin Finck
115*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__ucopy_ptrs(_InputIter __first,_InputIter __last,_OutputIter __result,const __true_type &)116*c2c66affSColin Finck inline _OutputIter __ucopy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
117*c2c66affSColin Finck const __true_type& /*TrivialUCopy*/) {
118*c2c66affSColin Finck // we know they all pointers, so this cast is OK
119*c2c66affSColin Finck // return (_OutputIter)__copy_trivial(&(*__first), &(*__last), &(*__result));
120*c2c66affSColin Finck return (_OutputIter)__ucopy_trivial(__first, __last, __result);
121*c2c66affSColin Finck }
122*c2c66affSColin Finck
123*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__ucopy_aux(_InputIter __first,_InputIter __last,_OutputIter __result,const __true_type &)124*c2c66affSColin Finck inline _OutputIter __ucopy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
125*c2c66affSColin Finck const __true_type& /*BothPtrType*/) {
126*c2c66affSColin Finck return __ucopy_ptrs(__first, __last, __result,
127*c2c66affSColin Finck _UseTrivialUCopy(_STLP_VALUE_TYPE(__first, _InputIter),
128*c2c66affSColin Finck _STLP_VALUE_TYPE(__result, _OutputIter))._Answer());
129*c2c66affSColin Finck }
130*c2c66affSColin Finck
131*c2c66affSColin Finck template <class _InputIter, class _OutputIter>
__ucopy_aux(_InputIter __first,_InputIter __last,_OutputIter __result,const __false_type &)132*c2c66affSColin Finck inline _OutputIter __ucopy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
133*c2c66affSColin Finck const __false_type& /*BothPtrType*/) {
134*c2c66affSColin Finck return __ucopy(__first, __last, __result,
135*c2c66affSColin Finck _STLP_ITERATOR_CATEGORY(__first, _InputIter),
136*c2c66affSColin Finck _STLP_DISTANCE_TYPE(__first, _InputIter));
137*c2c66affSColin Finck }
138*c2c66affSColin Finck
139*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
140*c2c66affSColin Finck
141*c2c66affSColin Finck template <class _InputIter, class _ForwardIter>
142*c2c66affSColin Finck inline _ForwardIter
uninitialized_copy(_InputIter __first,_InputIter __last,_ForwardIter __result)143*c2c66affSColin Finck uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result)
144*c2c66affSColin Finck { return _STLP_PRIV __ucopy_aux(__first, __last, __result, _BothPtrType< _InputIter, _ForwardIter>::_Answer()); }
145*c2c66affSColin Finck
146*c2c66affSColin Finck inline char*
uninitialized_copy(const char * __first,const char * __last,char * __result)147*c2c66affSColin Finck uninitialized_copy(const char* __first, const char* __last, char* __result)
148*c2c66affSColin Finck { return (char*)_STLP_PRIV __ucopy_trivial(__first, __last, __result); }
149*c2c66affSColin Finck
150*c2c66affSColin Finck # if defined (_STLP_HAS_WCHAR_T) // dwa 8/15/97
151*c2c66affSColin Finck inline wchar_t*
uninitialized_copy(const wchar_t * __first,const wchar_t * __last,wchar_t * __result)152*c2c66affSColin Finck uninitialized_copy(const wchar_t* __first, const wchar_t* __last, wchar_t* __result)
153*c2c66affSColin Finck { return (wchar_t*)_STLP_PRIV __ucopy_trivial (__first, __last, __result); }
154*c2c66affSColin Finck # endif
155*c2c66affSColin Finck
156*c2c66affSColin Finck // uninitialized_copy_n (not part of the C++ standard)
157*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
158*c2c66affSColin Finck
159*c2c66affSColin Finck template <class _InputIter, class _Size, class _ForwardIter>
160*c2c66affSColin Finck _STLP_INLINE_LOOP
161*c2c66affSColin Finck pair<_InputIter, _ForwardIter>
__ucopy_n(_InputIter __first,_Size __count,_ForwardIter __result,const input_iterator_tag &)162*c2c66affSColin Finck __ucopy_n(_InputIter __first, _Size __count, _ForwardIter __result,
163*c2c66affSColin Finck const input_iterator_tag &) {
164*c2c66affSColin Finck _ForwardIter __cur = __result;
165*c2c66affSColin Finck _STLP_TRY {
166*c2c66affSColin Finck for ( ; __count > 0 ; --__count, ++__first, ++__cur)
167*c2c66affSColin Finck _Param_Construct(&*__cur, *__first);
168*c2c66affSColin Finck return pair<_InputIter, _ForwardIter>(__first, __cur);
169*c2c66affSColin Finck }
170*c2c66affSColin Finck _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __cur))
171*c2c66affSColin Finck _STLP_RET_AFTER_THROW((pair<_InputIter, _ForwardIter>(__first, __cur)))
172*c2c66affSColin Finck }
173*c2c66affSColin Finck
174*c2c66affSColin Finck # if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
175*c2c66affSColin Finck template <class _InputIter, class _Size, class _ForwardIterator>
176*c2c66affSColin Finck inline pair<_InputIter, _ForwardIterator>
__ucopy_n(_InputIter __first,_Size __count,_ForwardIterator __result,const forward_iterator_tag &)177*c2c66affSColin Finck __ucopy_n(_InputIter __first, _Size __count,
178*c2c66affSColin Finck _ForwardIterator __result,
179*c2c66affSColin Finck const forward_iterator_tag &)
180*c2c66affSColin Finck { return __ucopy_n(__first, __count, __result, input_iterator_tag()); }
181*c2c66affSColin Finck
182*c2c66affSColin Finck template <class _InputIter, class _Size, class _ForwardIterator>
183*c2c66affSColin Finck inline pair<_InputIter, _ForwardIterator>
__ucopy_n(_InputIter __first,_Size __count,_ForwardIterator __result,const bidirectional_iterator_tag &)184*c2c66affSColin Finck __ucopy_n(_InputIter __first, _Size __count,
185*c2c66affSColin Finck _ForwardIterator __result,
186*c2c66affSColin Finck const bidirectional_iterator_tag &)
187*c2c66affSColin Finck { return __ucopy_n(__first, __count, __result, input_iterator_tag()); }
188*c2c66affSColin Finck # endif
189*c2c66affSColin Finck
190*c2c66affSColin Finck template <class _RandomAccessIter, class _Size, class _ForwardIter>
191*c2c66affSColin Finck inline pair<_RandomAccessIter, _ForwardIter>
__ucopy_n(_RandomAccessIter __first,_Size __count,_ForwardIter __result,const random_access_iterator_tag &)192*c2c66affSColin Finck __ucopy_n(_RandomAccessIter __first, _Size __count, _ForwardIter __result,
193*c2c66affSColin Finck const random_access_iterator_tag &) {
194*c2c66affSColin Finck _RandomAccessIter __last = __first + __count;
195*c2c66affSColin Finck return pair<_RandomAccessIter, _ForwardIter>(__last, uninitialized_copy(__first, __last, __result));
196*c2c66affSColin Finck }
197*c2c66affSColin Finck
198*c2c66affSColin Finck // This is used internally in <rope> , which is extension itself.
199*c2c66affSColin Finck template <class _InputIter, class _Size, class _ForwardIter>
200*c2c66affSColin Finck inline pair<_InputIter, _ForwardIter>
__ucopy_n(_InputIter __first,_Size __count,_ForwardIter __result)201*c2c66affSColin Finck __ucopy_n(_InputIter __first, _Size __count, _ForwardIter __result)
202*c2c66affSColin Finck { return _STLP_PRIV __ucopy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); }
203*c2c66affSColin Finck
204*c2c66affSColin Finck #if !defined (_STLP_NO_EXTENSIONS)
205*c2c66affSColin Finck
206*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
207*c2c66affSColin Finck
208*c2c66affSColin Finck template <class _InputIter, class _Size, class _ForwardIter>
209*c2c66affSColin Finck inline pair<_InputIter, _ForwardIter>
uninitialized_copy_n(_InputIter __first,_Size __count,_ForwardIter __result)210*c2c66affSColin Finck uninitialized_copy_n(_InputIter __first, _Size __count, _ForwardIter __result)
211*c2c66affSColin Finck { return _STLP_PRIV __ucopy_n(__first, __count, __result); }
212*c2c66affSColin Finck
213*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
214*c2c66affSColin Finck
215*c2c66affSColin Finck #endif
216*c2c66affSColin Finck
217*c2c66affSColin Finck template <class _ForwardIter, class _Tp, class _Distance>
__ufill(_ForwardIter __first,_ForwardIter __last,const _Tp & __x,_Distance *)218*c2c66affSColin Finck inline void __ufill(_ForwardIter __first, _ForwardIter __last, const _Tp& __x, _Distance*) {
219*c2c66affSColin Finck _ForwardIter __cur = __first;
220*c2c66affSColin Finck _STLP_TRY {
221*c2c66affSColin Finck for ( ; __cur != __last; ++__cur)
222*c2c66affSColin Finck _Param_Construct(&*__cur, __x);
223*c2c66affSColin Finck }
224*c2c66affSColin Finck _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first, __cur))
225*c2c66affSColin Finck }
226*c2c66affSColin Finck
227*c2c66affSColin Finck template <class _ForwardIter, class _Tp, class _Distance>
__ufill(_ForwardIter __first,_ForwardIter __last,const _Tp & __x,const input_iterator_tag &,_Distance * __d)228*c2c66affSColin Finck inline void __ufill(_ForwardIter __first, _ForwardIter __last,
229*c2c66affSColin Finck const _Tp& __x, const input_iterator_tag &, _Distance* __d)
230*c2c66affSColin Finck { __ufill(__first, __last, __x, __d); }
231*c2c66affSColin Finck
232*c2c66affSColin Finck #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
233*c2c66affSColin Finck template <class _ForwardIter, class _Tp, class _Distance>
__ufill(_ForwardIter __first,_ForwardIter __last,const _Tp & __x,const forward_iterator_tag &,_Distance * __d)234*c2c66affSColin Finck inline void __ufill(_ForwardIter __first, _ForwardIter __last,
235*c2c66affSColin Finck const _Tp& __x, const forward_iterator_tag &, _Distance* __d)
236*c2c66affSColin Finck { __ufill(__first, __last, __x, __d); }
237*c2c66affSColin Finck
238*c2c66affSColin Finck template <class _ForwardIter, class _Tp, class _Distance>
__ufill(_ForwardIter __first,_ForwardIter __last,const _Tp & __x,const bidirectional_iterator_tag &,_Distance * __d)239*c2c66affSColin Finck inline void __ufill(_ForwardIter __first, _ForwardIter __last,
240*c2c66affSColin Finck const _Tp& __x, const bidirectional_iterator_tag &, _Distance* __d)
241*c2c66affSColin Finck { __ufill(__first, __last, __x, __d); }
242*c2c66affSColin Finck #endif
243*c2c66affSColin Finck
244*c2c66affSColin Finck template <class _ForwardIter, class _Tp, class _Distance>
__ufill(_ForwardIter __first,_ForwardIter __last,const _Tp & __x,const random_access_iterator_tag &,_Distance *)245*c2c66affSColin Finck inline void __ufill(_ForwardIter __first, _ForwardIter __last,
246*c2c66affSColin Finck const _Tp& __x, const random_access_iterator_tag &, _Distance*) {
247*c2c66affSColin Finck _ForwardIter __cur = __first;
248*c2c66affSColin Finck _STLP_TRY {
249*c2c66affSColin Finck for (_Distance __n = __last - __first; __n > 0; --__n, ++__cur)
250*c2c66affSColin Finck _Param_Construct(&*__cur, __x);
251*c2c66affSColin Finck }
252*c2c66affSColin Finck _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first, __cur))
253*c2c66affSColin Finck }
254*c2c66affSColin Finck
255*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
256*c2c66affSColin Finck
257*c2c66affSColin Finck template <class _ForwardIter, class _Tp>
uninitialized_fill(_ForwardIter __first,_ForwardIter __last,const _Tp & __x)258*c2c66affSColin Finck inline void uninitialized_fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __x) {
259*c2c66affSColin Finck _STLP_PRIV __ufill(__first, __last, __x,
260*c2c66affSColin Finck _STLP_ITERATOR_CATEGORY(__first, _ForwardIter),
261*c2c66affSColin Finck _STLP_DISTANCE_TYPE(__first, _ForwardIter));
262*c2c66affSColin Finck }
263*c2c66affSColin Finck
264*c2c66affSColin Finck // Specialization: for one-byte types we can use memset.
uninitialized_fill(unsigned char * __first,unsigned char * __last,const unsigned char & __val)265*c2c66affSColin Finck inline void uninitialized_fill(unsigned char* __first, unsigned char* __last,
266*c2c66affSColin Finck const unsigned char& __val) {
267*c2c66affSColin Finck unsigned char __tmp = __val;
268*c2c66affSColin Finck memset(__first, __tmp, __last - __first);
269*c2c66affSColin Finck }
270*c2c66affSColin Finck #if !defined (_STLP_NO_SIGNED_BUILTINS)
uninitialized_fill(signed char * __first,signed char * __last,const signed char & __val)271*c2c66affSColin Finck inline void uninitialized_fill(signed char* __first, signed char* __last,
272*c2c66affSColin Finck const signed char& __val) {
273*c2c66affSColin Finck signed char __tmp = __val;
274*c2c66affSColin Finck memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
275*c2c66affSColin Finck }
276*c2c66affSColin Finck #endif
uninitialized_fill(char * __first,char * __last,const char & __val)277*c2c66affSColin Finck inline void uninitialized_fill(char* __first, char* __last, const char& __val) {
278*c2c66affSColin Finck char __tmp = __val;
279*c2c66affSColin Finck memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
280*c2c66affSColin Finck }
281*c2c66affSColin Finck
282*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
283*c2c66affSColin Finck
284*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__ufill_n(_ForwardIter __first,_Size __n,const _Tp & __x)285*c2c66affSColin Finck inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x) {
286*c2c66affSColin Finck _ForwardIter __cur = __first;
287*c2c66affSColin Finck _STLP_TRY {
288*c2c66affSColin Finck for ( ; __n > 0; --__n, ++__cur)
289*c2c66affSColin Finck _Param_Construct(&*__cur, __x);
290*c2c66affSColin Finck }
291*c2c66affSColin Finck _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first, __cur))
292*c2c66affSColin Finck return __cur;
293*c2c66affSColin Finck }
294*c2c66affSColin Finck
295*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__ufill_n(_ForwardIter __first,_Size __n,const _Tp & __x,const input_iterator_tag &)296*c2c66affSColin Finck inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
297*c2c66affSColin Finck const input_iterator_tag &)
298*c2c66affSColin Finck { return __ufill_n(__first, __n, __x); }
299*c2c66affSColin Finck
300*c2c66affSColin Finck #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
301*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__ufill_n(_ForwardIter __first,_Size __n,const _Tp & __x,const forward_iterator_tag &)302*c2c66affSColin Finck inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
303*c2c66affSColin Finck const forward_iterator_tag &)
304*c2c66affSColin Finck { return __ufill_n(__first, __n, __x); }
305*c2c66affSColin Finck
306*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__ufill_n(_ForwardIter __first,_Size __n,const _Tp & __x,const bidirectional_iterator_tag &)307*c2c66affSColin Finck inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
308*c2c66affSColin Finck const bidirectional_iterator_tag &)
309*c2c66affSColin Finck { return __ufill_n(__first, __n, __x); }
310*c2c66affSColin Finck #endif
311*c2c66affSColin Finck
312*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__uninitialized_fill_n(_ForwardIter __first,_Size __n,const _Tp & __x)313*c2c66affSColin Finck inline _ForwardIter __uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x) {
314*c2c66affSColin Finck _ForwardIter __last = __first + __n;
315*c2c66affSColin Finck __ufill(__first, __last, __x, random_access_iterator_tag(), (ptrdiff_t*)0);
316*c2c66affSColin Finck return __last;
317*c2c66affSColin Finck }
318*c2c66affSColin Finck
319*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__ufill_n(_ForwardIter __first,_Size __n,const _Tp & __x,const random_access_iterator_tag &)320*c2c66affSColin Finck inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
321*c2c66affSColin Finck const random_access_iterator_tag &)
322*c2c66affSColin Finck { return __uninitialized_fill_n(__first, __n, __x); }
323*c2c66affSColin Finck
324*c2c66affSColin Finck /* __uninitialized_init is an internal algo to init a range with a value
325*c2c66affSColin Finck * built using default constructor. It is only called with pointer as
326*c2c66affSColin Finck * iterator.
327*c2c66affSColin Finck */
328*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__uinit_aux_aux(_ForwardIter __first,_Size __n,const _Tp & __val,const __false_type &)329*c2c66affSColin Finck inline _ForwardIter __uinit_aux_aux(_ForwardIter __first, _Size __n, const _Tp& __val,
330*c2c66affSColin Finck const __false_type& /*_HasDefaultZero*/)
331*c2c66affSColin Finck { return __uninitialized_fill_n(__first, __n, __val); }
332*c2c66affSColin Finck
333*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__uinit_aux_aux(_ForwardIter __first,_Size __n,const _Tp &,const __true_type &)334*c2c66affSColin Finck inline _ForwardIter __uinit_aux_aux(_ForwardIter __first, _Size __n, const _Tp& /* __val */,
335*c2c66affSColin Finck const __true_type& /*_HasDefaultZero*/) {
336*c2c66affSColin Finck memset((unsigned char*)__first, 0, __n * sizeof(_Tp));
337*c2c66affSColin Finck return __first + __n;
338*c2c66affSColin Finck }
339*c2c66affSColin Finck
340*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__uinit_aux(_ForwardIter __first,_Size __n,const _Tp &,const __true_type &)341*c2c66affSColin Finck inline _ForwardIter __uinit_aux(_ForwardIter __first, _Size __n, const _Tp&,
342*c2c66affSColin Finck const __true_type& /*_TrivialInit*/)
343*c2c66affSColin Finck { return __first + __n; }
344*c2c66affSColin Finck
345*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__uinit_aux(_ForwardIter __first,_Size __n,const _Tp & __val,const __false_type &)346*c2c66affSColin Finck inline _ForwardIter __uinit_aux(_ForwardIter __first, _Size __n, const _Tp& __val,
347*c2c66affSColin Finck const __false_type& /*_TrivialInit*/)
348*c2c66affSColin Finck { return __uinit_aux_aux(__first, __n, __val, _HasDefaultZeroValue(__first)._Answer()); }
349*c2c66affSColin Finck
350*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
__uninitialized_init(_ForwardIter __first,_Size __n,const _Tp & __val)351*c2c66affSColin Finck inline _ForwardIter __uninitialized_init(_ForwardIter __first, _Size __n, const _Tp& __val)
352*c2c66affSColin Finck { return __uinit_aux(__first, __n, __val, _UseTrivialInit(__first)._Answer()); }
353*c2c66affSColin Finck
354*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
355*c2c66affSColin Finck
356*c2c66affSColin Finck template <class _ForwardIter, class _Size, class _Tp>
357*c2c66affSColin Finck inline void
uninitialized_fill_n(_ForwardIter __first,_Size __n,const _Tp & __x)358*c2c66affSColin Finck uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x)
359*c2c66affSColin Finck { _STLP_PRIV __ufill_n(__first, __n, __x, _STLP_ITERATOR_CATEGORY(__first, _ForwardIter)); }
360*c2c66affSColin Finck
361*c2c66affSColin Finck // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill,
362*c2c66affSColin Finck // __uninitialized_fill_copy.
363*c2c66affSColin Finck
364*c2c66affSColin Finck // __uninitialized_copy_copy
365*c2c66affSColin Finck // Copies [first1, last1) into [result, result + (last1 - first1)), and
366*c2c66affSColin Finck // copies [first2, last2) into
367*c2c66affSColin Finck // [result + (last1 - first1), result + (last1 - first1) + (last2 - first2)).
368*c2c66affSColin Finck
369*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
370*c2c66affSColin Finck
371*c2c66affSColin Finck template <class _InputIter1, class _InputIter2, class _ForwardIter>
372*c2c66affSColin Finck inline _ForwardIter
__uninitialized_copy_copy(_InputIter1 __first1,_InputIter1 __last1,_InputIter2 __first2,_InputIter2 __last2,_ForwardIter __result)373*c2c66affSColin Finck __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
374*c2c66affSColin Finck _InputIter2 __first2, _InputIter2 __last2,
375*c2c66affSColin Finck _ForwardIter __result) {
376*c2c66affSColin Finck _ForwardIter __new_result = uninitialized_copy(__first1, __last1, __result);
377*c2c66affSColin Finck _STLP_TRY {
378*c2c66affSColin Finck return uninitialized_copy(__first2, __last2, __new_result);
379*c2c66affSColin Finck }
380*c2c66affSColin Finck _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __new_result))
381*c2c66affSColin Finck _STLP_RET_AFTER_THROW(__result)
382*c2c66affSColin Finck }
383*c2c66affSColin Finck
384*c2c66affSColin Finck // __uninitialized_fill_copy
385*c2c66affSColin Finck // Fills [result, mid) with x, and copies [first, last) into
386*c2c66affSColin Finck // [mid, mid + (last - first)).
387*c2c66affSColin Finck template <class _ForwardIter, class _Tp, class _InputIter>
388*c2c66affSColin Finck inline _ForwardIter
__uninitialized_fill_copy(_ForwardIter __result,_ForwardIter __mid,const _Tp & __x,_InputIter __first,_InputIter __last)389*c2c66affSColin Finck __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid, const _Tp& __x,
390*c2c66affSColin Finck _InputIter __first, _InputIter __last) {
391*c2c66affSColin Finck uninitialized_fill(__result, __mid, __x);
392*c2c66affSColin Finck _STLP_TRY {
393*c2c66affSColin Finck return uninitialized_copy(__first, __last, __mid);
394*c2c66affSColin Finck }
395*c2c66affSColin Finck _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __mid))
396*c2c66affSColin Finck _STLP_RET_AFTER_THROW(__result)
397*c2c66affSColin Finck }
398*c2c66affSColin Finck
399*c2c66affSColin Finck // __uninitialized_copy_fill
400*c2c66affSColin Finck // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
401*c2c66affSColin Finck // fills [first2 + (last1 - first1), last2) with x.
402*c2c66affSColin Finck template <class _Iter, class _Tp>
403*c2c66affSColin Finck inline void
__uninitialized_copy_fill(_Iter __first1,_Iter __last1,_Iter __first2,_Iter __last2,const _Tp & __x)404*c2c66affSColin Finck __uninitialized_copy_fill(_Iter __first1, _Iter __last1, _Iter __first2, _Iter __last2,
405*c2c66affSColin Finck const _Tp& __x) {
406*c2c66affSColin Finck _Iter __mid2 = uninitialized_copy(__first1, __last1, __first2);
407*c2c66affSColin Finck _STLP_TRY {
408*c2c66affSColin Finck uninitialized_fill(__mid2, __last2, __x);
409*c2c66affSColin Finck }
410*c2c66affSColin Finck _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first2, __mid2))
411*c2c66affSColin Finck }
412*c2c66affSColin Finck
413*c2c66affSColin Finck /* __uninitialized_move:
414*c2c66affSColin Finck * This function is used internaly and only with pointers as iterators.
415*c2c66affSColin Finck */
416*c2c66affSColin Finck template <class _InputIter, class _ForwardIter, class _TrivialUCpy>
417*c2c66affSColin Finck inline _ForwardIter
__uninitialized_move(_InputIter __first,_InputIter __last,_ForwardIter __result,_TrivialUCpy __trivial_ucpy,const __false_type &)418*c2c66affSColin Finck __uninitialized_move(_InputIter __first, _InputIter __last, _ForwardIter __result,
419*c2c66affSColin Finck _TrivialUCpy __trivial_ucpy, const __false_type& /*_Movable*/)
420*c2c66affSColin Finck { return __ucopy_ptrs(__first, __last, __result, __trivial_ucpy); }
421*c2c66affSColin Finck
422*c2c66affSColin Finck template <class _InputIter, class _ForwardIter, class _TrivialUCpy>
423*c2c66affSColin Finck _STLP_INLINE_LOOP
424*c2c66affSColin Finck _ForwardIter
__uninitialized_move(_InputIter __first,_InputIter __last,_ForwardIter __result,_TrivialUCpy,const __true_type &)425*c2c66affSColin Finck __uninitialized_move(_InputIter __first, _InputIter __last, _ForwardIter __result,
426*c2c66affSColin Finck _TrivialUCpy , const __true_type& /*_Movable*/) {
427*c2c66affSColin Finck //Move constructor should not throw so we do not need to take care of exceptions here.
428*c2c66affSColin Finck for (ptrdiff_t __n = __last - __first ; __n > 0; --__n) {
429*c2c66affSColin Finck _Move_Construct(&*__result, *__first);
430*c2c66affSColin Finck ++__first; ++__result;
431*c2c66affSColin Finck }
432*c2c66affSColin Finck return __result;
433*c2c66affSColin Finck }
434*c2c66affSColin Finck
435*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
436*c2c66affSColin Finck
437*c2c66affSColin Finck _STLP_END_NAMESPACE
438*c2c66affSColin Finck
439*c2c66affSColin Finck #endif /* _STLP_INTERNAL_UNINITIALIZED_H */
440*c2c66affSColin Finck
441*c2c66affSColin Finck // Local Variables:
442*c2c66affSColin Finck // mode:C++
443*c2c66affSColin Finck // End:
444