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