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