]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/stl_uninitialized.h
algo.h: Use std not __STD.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / stl_uninitialized.h
1 /*
2 *
3 * Copyright (c) 1994
4 * Hewlett-Packard Company
5 *
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.
13 *
14 *
15 * Copyright (c) 1996,1997
16 * Silicon Graphics Computer Systems, Inc.
17 *
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.
25 */
26
27 /* NOTE: This is an internal header file, included by other STL headers.
28 * You should not attempt to use it directly.
29 */
30
31 #ifndef _CPP_BITS_STL_UNINITIALIZED_H
32 #define _CPP_BITS_STL_UNINITIALIZED_H 1
33
34 #include <bits/std_cstring.h>
35
36 namespace std
37 {
38
39 // uninitialized_copy
40
41 // Valid if copy construction is equivalent to assignment, and if the
42 // destructor is trivial.
43 template <class _InputIter, class _ForwardIter>
44 inline _ForwardIter
45 __uninitialized_copy_aux(_InputIter __first, _InputIter __last,
46 _ForwardIter __result,
47 __true_type)
48 {
49 return copy(__first, __last, __result);
50 }
51
52 template <class _InputIter, class _ForwardIter>
53 _ForwardIter
54 __uninitialized_copy_aux(_InputIter __first, _InputIter __last,
55 _ForwardIter __result,
56 __false_type)
57 {
58 _ForwardIter __cur = __result;
59 __STL_TRY {
60 for ( ; __first != __last; ++__first, ++__cur)
61 _Construct(&*__cur, *__first);
62 return __cur;
63 }
64 __STL_UNWIND(_Destroy(__result, __cur));
65 }
66
67
68 template <class _InputIter, class _ForwardIter, class _Tp>
69 inline _ForwardIter
70 __uninitialized_copy(_InputIter __first, _InputIter __last,
71 _ForwardIter __result, _Tp*)
72 {
73 typedef typename __type_traits<_Tp>::is_POD_type _Is_POD;
74 return __uninitialized_copy_aux(__first, __last, __result, _Is_POD());
75 }
76
77 template <class _InputIter, class _ForwardIter>
78 inline _ForwardIter
79 uninitialized_copy(_InputIter __first, _InputIter __last,
80 _ForwardIter __result)
81 {
82 return __uninitialized_copy(__first, __last, __result,
83 __VALUE_TYPE(__result));
84 }
85
86 inline char* uninitialized_copy(const char* __first, const char* __last,
87 char* __result) {
88 memmove(__result, __first, __last - __first);
89 return __result + (__last - __first);
90 }
91
92 inline wchar_t*
93 uninitialized_copy(const wchar_t* __first, const wchar_t* __last,
94 wchar_t* __result)
95 {
96 memmove(__result, __first, sizeof(wchar_t) * (__last - __first));
97 return __result + (__last - __first);
98 }
99
100 // uninitialized_copy_n (not part of the C++ standard)
101
102 template <class _InputIter, class _Size, class _ForwardIter>
103 pair<_InputIter, _ForwardIter>
104 __uninitialized_copy_n(_InputIter __first, _Size __count,
105 _ForwardIter __result,
106 input_iterator_tag)
107 {
108 _ForwardIter __cur = __result;
109 __STL_TRY {
110 for ( ; __count > 0 ; --__count, ++__first, ++__cur)
111 _Construct(&*__cur, *__first);
112 return pair<_InputIter, _ForwardIter>(__first, __cur);
113 }
114 __STL_UNWIND(_Destroy(__result, __cur));
115 }
116
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>(
124 __last,
125 uninitialized_copy(__first, __last, __result));
126 }
127
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));
134 }
135
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));
142 }
143
144 // Valid if copy construction is equivalent to assignment, and if the
145 // destructor is trivial.
146 template <class _ForwardIter, class _Tp>
147 inline void
148 __uninitialized_fill_aux(_ForwardIter __first, _ForwardIter __last,
149 const _Tp& __x, __true_type)
150 {
151 fill(__first, __last, __x);
152 }
153
154 template <class _ForwardIter, class _Tp>
155 void
156 __uninitialized_fill_aux(_ForwardIter __first, _ForwardIter __last,
157 const _Tp& __x, __false_type)
158 {
159 _ForwardIter __cur = __first;
160 __STL_TRY {
161 for ( ; __cur != __last; ++__cur)
162 _Construct(&*__cur, __x);
163 }
164 __STL_UNWIND(_Destroy(__first, __cur));
165 }
166
167 template <class _ForwardIter, class _Tp, class _Tp1>
168 inline void __uninitialized_fill(_ForwardIter __first,
169 _ForwardIter __last, const _Tp& __x, _Tp1*)
170 {
171 typedef typename __type_traits<_Tp1>::is_POD_type _Is_POD;
172 __uninitialized_fill_aux(__first, __last, __x, _Is_POD());
173
174 }
175
176 template <class _ForwardIter, class _Tp>
177 inline void uninitialized_fill(_ForwardIter __first,
178 _ForwardIter __last,
179 const _Tp& __x)
180 {
181 __uninitialized_fill(__first, __last, __x, __VALUE_TYPE(__first));
182 }
183
184 // Valid if copy construction is equivalent to assignment, and if the
185 // destructor is trivial.
186 template <class _ForwardIter, class _Size, class _Tp>
187 inline _ForwardIter
188 __uninitialized_fill_n_aux(_ForwardIter __first, _Size __n,
189 const _Tp& __x, __true_type)
190 {
191 return fill_n(__first, __n, __x);
192 }
193
194 template <class _ForwardIter, class _Size, class _Tp>
195 _ForwardIter
196 __uninitialized_fill_n_aux(_ForwardIter __first, _Size __n,
197 const _Tp& __x, __false_type)
198 {
199 _ForwardIter __cur = __first;
200 __STL_TRY {
201 for ( ; __n > 0; --__n, ++__cur)
202 _Construct(&*__cur, __x);
203 return __cur;
204 }
205 __STL_UNWIND(_Destroy(__first, __cur));
206 }
207
208 template <class _ForwardIter, class _Size, class _Tp, class _Tp1>
209 inline _ForwardIter
210 __uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x, _Tp1*)
211 {
212 typedef typename __type_traits<_Tp1>::is_POD_type _Is_POD;
213 return __uninitialized_fill_n_aux(__first, __n, __x, _Is_POD());
214 }
215
216 template <class _ForwardIter, class _Size, class _Tp>
217 inline _ForwardIter
218 uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x)
219 {
220 return __uninitialized_fill_n(__first, __n, __x, __VALUE_TYPE(__first));
221 }
222
223 // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill,
224 // __uninitialized_fill_copy.
225
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)).
230
231 template <class _InputIter1, class _InputIter2, class _ForwardIter>
232 inline _ForwardIter
233 __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
234 _InputIter2 __first2, _InputIter2 __last2,
235 _ForwardIter __result)
236 {
237 _ForwardIter __mid = uninitialized_copy(__first1, __last1, __result);
238 __STL_TRY {
239 return uninitialized_copy(__first2, __last2, __mid);
240 }
241 __STL_UNWIND(_Destroy(__result, __mid));
242 }
243
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>
248 inline _ForwardIter
249 __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid,
250 const _Tp& __x,
251 _InputIter __first, _InputIter __last)
252 {
253 uninitialized_fill(__result, __mid, __x);
254 __STL_TRY {
255 return uninitialized_copy(__first, __last, __mid);
256 }
257 __STL_UNWIND(_Destroy(__result, __mid));
258 }
259
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>
264 inline void
265 __uninitialized_copy_fill(_InputIter __first1, _InputIter __last1,
266 _ForwardIter __first2, _ForwardIter __last2,
267 const _Tp& __x)
268 {
269 _ForwardIter __mid2 = uninitialized_copy(__first1, __last1, __first2);
270 __STL_TRY {
271 uninitialized_fill(__mid2, __last2, __x);
272 }
273 __STL_UNWIND(_Destroy(__first2, __mid2));
274 }
275
276 } // namespace std
277
278 #endif /* _CPP_BITS_STL_UNINITIALIZED_H */
279
280 // Local Variables:
281 // mode:C++
282 // End: