4 * Hewlett-Packard Company
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation. Hewlett-Packard Company makes no
11 * representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
15 * Copyright (c) 1996,1997
16 * Silicon Graphics Computer Systems, Inc.
18 * Permission to use, copy, modify, distribute and sell this software
19 * and its documentation for any purpose is hereby granted without fee,
20 * provided that the above copyright notice appear in all copies and
21 * that both that copyright notice and this permission notice appear
22 * in supporting documentation. Silicon Graphics makes no
23 * representations about the suitability of this software for any
24 * purpose. It is provided "as is" without express or implied warranty.
27 /* NOTE: This is an internal header file, included by other STL headers.
28 * You should not attempt to use it directly.
31 #ifndef _CPP_BITS_STL_UNINITIALIZED_H
32 #define _CPP_BITS_STL_UNINITIALIZED_H 1
34 #include <bits/std_cstring.h>
41 // Valid if copy construction is equivalent to assignment, and if the
42 // destructor is trivial.
43 template <class _InputIter
, class _ForwardIter
>
45 __uninitialized_copy_aux(_InputIter __first
, _InputIter __last
,
46 _ForwardIter __result
,
49 return copy(__first
, __last
, __result
);
52 template <class _InputIter
, class _ForwardIter
>
54 __uninitialized_copy_aux(_InputIter __first
, _InputIter __last
,
55 _ForwardIter __result
,
58 _ForwardIter __cur
= __result
;
60 for ( ; __first
!= __last
; ++__first
, ++__cur
)
61 _Construct(&*__cur
, *__first
);
64 __STL_UNWIND(_Destroy(__result
, __cur
));
68 template <class _InputIter
, class _ForwardIter
, class _Tp
>
70 __uninitialized_copy(_InputIter __first
, _InputIter __last
,
71 _ForwardIter __result
, _Tp
*)
73 typedef typename __type_traits
<_Tp
>::is_POD_type _Is_POD
;
74 return __uninitialized_copy_aux(__first
, __last
, __result
, _Is_POD());
77 template <class _InputIter
, class _ForwardIter
>
79 uninitialized_copy(_InputIter __first
, _InputIter __last
,
80 _ForwardIter __result
)
82 return __uninitialized_copy(__first
, __last
, __result
,
83 __VALUE_TYPE(__result
));
86 inline char* uninitialized_copy(const char* __first
, const char* __last
,
88 memmove(__result
, __first
, __last
- __first
);
89 return __result
+ (__last
- __first
);
93 uninitialized_copy(const wchar_t* __first
, const wchar_t* __last
,
96 memmove(__result
, __first
, sizeof(wchar_t) * (__last
- __first
));
97 return __result
+ (__last
- __first
);
100 // uninitialized_copy_n (not part of the C++ standard)
102 template <class _InputIter
, class _Size
, class _ForwardIter
>
103 pair
<_InputIter
, _ForwardIter
>
104 __uninitialized_copy_n(_InputIter __first
, _Size __count
,
105 _ForwardIter __result
,
108 _ForwardIter __cur
= __result
;
110 for ( ; __count
> 0 ; --__count
, ++__first
, ++__cur
)
111 _Construct(&*__cur
, *__first
);
112 return pair
<_InputIter
, _ForwardIter
>(__first
, __cur
);
114 __STL_UNWIND(_Destroy(__result
, __cur
));
117 template <class _RandomAccessIter
, class _Size
, class _ForwardIter
>
118 inline pair
<_RandomAccessIter
, _ForwardIter
>
119 __uninitialized_copy_n(_RandomAccessIter __first
, _Size __count
,
120 _ForwardIter __result
,
121 random_access_iterator_tag
) {
122 _RandomAccessIter __last
= __first
+ __count
;
123 return pair
<_RandomAccessIter
, _ForwardIter
>(
125 uninitialized_copy(__first
, __last
, __result
));
128 template <class _InputIter
, class _Size
, class _ForwardIter
>
129 inline pair
<_InputIter
, _ForwardIter
>
130 __uninitialized_copy_n(_InputIter __first
, _Size __count
,
131 _ForwardIter __result
) {
132 return __uninitialized_copy_n(__first
, __count
, __result
,
133 __ITERATOR_CATEGORY(__first
));
136 template <class _InputIter
, class _Size
, class _ForwardIter
>
137 inline pair
<_InputIter
, _ForwardIter
>
138 uninitialized_copy_n(_InputIter __first
, _Size __count
,
139 _ForwardIter __result
) {
140 return __uninitialized_copy_n(__first
, __count
, __result
,
141 __ITERATOR_CATEGORY(__first
));
144 // Valid if copy construction is equivalent to assignment, and if the
145 // destructor is trivial.
146 template <class _ForwardIter
, class _Tp
>
148 __uninitialized_fill_aux(_ForwardIter __first
, _ForwardIter __last
,
149 const _Tp
& __x
, __true_type
)
151 fill(__first
, __last
, __x
);
154 template <class _ForwardIter
, class _Tp
>
156 __uninitialized_fill_aux(_ForwardIter __first
, _ForwardIter __last
,
157 const _Tp
& __x
, __false_type
)
159 _ForwardIter __cur
= __first
;
161 for ( ; __cur
!= __last
; ++__cur
)
162 _Construct(&*__cur
, __x
);
164 __STL_UNWIND(_Destroy(__first
, __cur
));
167 template <class _ForwardIter
, class _Tp
, class _Tp1
>
168 inline void __uninitialized_fill(_ForwardIter __first
,
169 _ForwardIter __last
, const _Tp
& __x
, _Tp1
*)
171 typedef typename __type_traits
<_Tp1
>::is_POD_type _Is_POD
;
172 __uninitialized_fill_aux(__first
, __last
, __x
, _Is_POD());
176 template <class _ForwardIter
, class _Tp
>
177 inline void uninitialized_fill(_ForwardIter __first
,
181 __uninitialized_fill(__first
, __last
, __x
, __VALUE_TYPE(__first
));
184 // Valid if copy construction is equivalent to assignment, and if the
185 // destructor is trivial.
186 template <class _ForwardIter
, class _Size
, class _Tp
>
188 __uninitialized_fill_n_aux(_ForwardIter __first
, _Size __n
,
189 const _Tp
& __x
, __true_type
)
191 return fill_n(__first
, __n
, __x
);
194 template <class _ForwardIter
, class _Size
, class _Tp
>
196 __uninitialized_fill_n_aux(_ForwardIter __first
, _Size __n
,
197 const _Tp
& __x
, __false_type
)
199 _ForwardIter __cur
= __first
;
201 for ( ; __n
> 0; --__n
, ++__cur
)
202 _Construct(&*__cur
, __x
);
205 __STL_UNWIND(_Destroy(__first
, __cur
));
208 template <class _ForwardIter
, class _Size
, class _Tp
, class _Tp1
>
210 __uninitialized_fill_n(_ForwardIter __first
, _Size __n
, const _Tp
& __x
, _Tp1
*)
212 typedef typename __type_traits
<_Tp1
>::is_POD_type _Is_POD
;
213 return __uninitialized_fill_n_aux(__first
, __n
, __x
, _Is_POD());
216 template <class _ForwardIter
, class _Size
, class _Tp
>
218 uninitialized_fill_n(_ForwardIter __first
, _Size __n
, const _Tp
& __x
)
220 return __uninitialized_fill_n(__first
, __n
, __x
, __VALUE_TYPE(__first
));
223 // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill,
224 // __uninitialized_fill_copy.
226 // __uninitialized_copy_copy
227 // Copies [first1, last1) into [result, result + (last1 - first1)), and
228 // copies [first2, last2) into
229 // [result, result + (last1 - first1) + (last2 - first2)).
231 template <class _InputIter1
, class _InputIter2
, class _ForwardIter
>
233 __uninitialized_copy_copy(_InputIter1 __first1
, _InputIter1 __last1
,
234 _InputIter2 __first2
, _InputIter2 __last2
,
235 _ForwardIter __result
)
237 _ForwardIter __mid
= uninitialized_copy(__first1
, __last1
, __result
);
239 return uninitialized_copy(__first2
, __last2
, __mid
);
241 __STL_UNWIND(_Destroy(__result
, __mid
));
244 // __uninitialized_fill_copy
245 // Fills [result, mid) with x, and copies [first, last) into
246 // [mid, mid + (last - first)).
247 template <class _ForwardIter
, class _Tp
, class _InputIter
>
249 __uninitialized_fill_copy(_ForwardIter __result
, _ForwardIter __mid
,
251 _InputIter __first
, _InputIter __last
)
253 uninitialized_fill(__result
, __mid
, __x
);
255 return uninitialized_copy(__first
, __last
, __mid
);
257 __STL_UNWIND(_Destroy(__result
, __mid
));
260 // __uninitialized_copy_fill
261 // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
262 // fills [first2 + (last1 - first1), last2) with x.
263 template <class _InputIter
, class _ForwardIter
, class _Tp
>
265 __uninitialized_copy_fill(_InputIter __first1
, _InputIter __last1
,
266 _ForwardIter __first2
, _ForwardIter __last2
,
269 _ForwardIter __mid2
= uninitialized_copy(__first1
, __last1
, __first2
);
271 uninitialized_fill(__mid2
, __last2
, __x
);
273 __STL_UNWIND(_Destroy(__first2
, __mid2
));
278 #endif /* _CPP_BITS_STL_UNINITIALIZED_H */