]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/stl_uninitialized.h
Implement P0040R3, Extending memory management tools.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / stl_uninitialized.h
1 // Raw memory manipulators -*- C++ -*-
2
3 // Copyright (C) 2001-2016 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 /*
26 *
27 * Copyright (c) 1994
28 * Hewlett-Packard Company
29 *
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
37 *
38 *
39 * Copyright (c) 1996,1997
40 * Silicon Graphics Computer Systems, Inc.
41 *
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
49 */
50
51 /** @file bits/stl_uninitialized.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{memory}
54 */
55
56 #ifndef _STL_UNINITIALIZED_H
57 #define _STL_UNINITIALIZED_H 1
58
59 #if __cplusplus > 201402L
60 #include <utility>
61 #endif
62
63 namespace std _GLIBCXX_VISIBILITY(default)
64 {
65 _GLIBCXX_BEGIN_NAMESPACE_VERSION
66
67 template<bool _TrivialValueTypes>
68 struct __uninitialized_copy
69 {
70 template<typename _InputIterator, typename _ForwardIterator>
71 static _ForwardIterator
72 __uninit_copy(_InputIterator __first, _InputIterator __last,
73 _ForwardIterator __result)
74 {
75 _ForwardIterator __cur = __result;
76 __try
77 {
78 for (; __first != __last; ++__first, (void)++__cur)
79 std::_Construct(std::__addressof(*__cur), *__first);
80 return __cur;
81 }
82 __catch(...)
83 {
84 std::_Destroy(__result, __cur);
85 __throw_exception_again;
86 }
87 }
88 };
89
90 template<>
91 struct __uninitialized_copy<true>
92 {
93 template<typename _InputIterator, typename _ForwardIterator>
94 static _ForwardIterator
95 __uninit_copy(_InputIterator __first, _InputIterator __last,
96 _ForwardIterator __result)
97 { return std::copy(__first, __last, __result); }
98 };
99
100 /**
101 * @brief Copies the range [first,last) into result.
102 * @param __first An input iterator.
103 * @param __last An input iterator.
104 * @param __result An output iterator.
105 * @return __result + (__first - __last)
106 *
107 * Like copy(), but does not require an initialized output range.
108 */
109 template<typename _InputIterator, typename _ForwardIterator>
110 inline _ForwardIterator
111 uninitialized_copy(_InputIterator __first, _InputIterator __last,
112 _ForwardIterator __result)
113 {
114 typedef typename iterator_traits<_InputIterator>::value_type
115 _ValueType1;
116 typedef typename iterator_traits<_ForwardIterator>::value_type
117 _ValueType2;
118 #if __cplusplus < 201103L
119 const bool __assignable = true;
120 #else
121 // trivial types can have deleted assignment
122 typedef typename iterator_traits<_InputIterator>::reference _RefType1;
123 typedef typename iterator_traits<_ForwardIterator>::reference _RefType2;
124 const bool __assignable = is_assignable<_RefType2, _RefType1>::value;
125 #endif
126
127 return std::__uninitialized_copy<__is_trivial(_ValueType1)
128 && __is_trivial(_ValueType2)
129 && __assignable>::
130 __uninit_copy(__first, __last, __result);
131 }
132
133
134 template<bool _TrivialValueType>
135 struct __uninitialized_fill
136 {
137 template<typename _ForwardIterator, typename _Tp>
138 static void
139 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
140 const _Tp& __x)
141 {
142 _ForwardIterator __cur = __first;
143 __try
144 {
145 for (; __cur != __last; ++__cur)
146 std::_Construct(std::__addressof(*__cur), __x);
147 }
148 __catch(...)
149 {
150 std::_Destroy(__first, __cur);
151 __throw_exception_again;
152 }
153 }
154 };
155
156 template<>
157 struct __uninitialized_fill<true>
158 {
159 template<typename _ForwardIterator, typename _Tp>
160 static void
161 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
162 const _Tp& __x)
163 { std::fill(__first, __last, __x); }
164 };
165
166 /**
167 * @brief Copies the value x into the range [first,last).
168 * @param __first An input iterator.
169 * @param __last An input iterator.
170 * @param __x The source value.
171 * @return Nothing.
172 *
173 * Like fill(), but does not require an initialized output range.
174 */
175 template<typename _ForwardIterator, typename _Tp>
176 inline void
177 uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last,
178 const _Tp& __x)
179 {
180 typedef typename iterator_traits<_ForwardIterator>::value_type
181 _ValueType;
182 #if __cplusplus < 201103L
183 const bool __assignable = true;
184 #else
185 // trivial types can have deleted assignment
186 const bool __assignable = is_copy_assignable<_ValueType>::value;
187 #endif
188
189 std::__uninitialized_fill<__is_trivial(_ValueType) && __assignable>::
190 __uninit_fill(__first, __last, __x);
191 }
192
193
194 template<bool _TrivialValueType>
195 struct __uninitialized_fill_n
196 {
197 template<typename _ForwardIterator, typename _Size, typename _Tp>
198 static _ForwardIterator
199 __uninit_fill_n(_ForwardIterator __first, _Size __n,
200 const _Tp& __x)
201 {
202 _ForwardIterator __cur = __first;
203 __try
204 {
205 for (; __n > 0; --__n, ++__cur)
206 std::_Construct(std::__addressof(*__cur), __x);
207 return __cur;
208 }
209 __catch(...)
210 {
211 std::_Destroy(__first, __cur);
212 __throw_exception_again;
213 }
214 }
215 };
216
217 template<>
218 struct __uninitialized_fill_n<true>
219 {
220 template<typename _ForwardIterator, typename _Size, typename _Tp>
221 static _ForwardIterator
222 __uninit_fill_n(_ForwardIterator __first, _Size __n,
223 const _Tp& __x)
224 { return std::fill_n(__first, __n, __x); }
225 };
226
227 // _GLIBCXX_RESOLVE_LIB_DEFECTS
228 // DR 1339. uninitialized_fill_n should return the end of its range
229 /**
230 * @brief Copies the value x into the range [first,first+n).
231 * @param __first An input iterator.
232 * @param __n The number of copies to make.
233 * @param __x The source value.
234 * @return Nothing.
235 *
236 * Like fill_n(), but does not require an initialized output range.
237 */
238 template<typename _ForwardIterator, typename _Size, typename _Tp>
239 inline _ForwardIterator
240 uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
241 {
242 typedef typename iterator_traits<_ForwardIterator>::value_type
243 _ValueType;
244 #if __cplusplus < 201103L
245 const bool __assignable = true;
246 #else
247 // trivial types can have deleted assignment
248 const bool __assignable = is_copy_assignable<_ValueType>::value;
249 #endif
250 return __uninitialized_fill_n<__is_trivial(_ValueType) && __assignable>::
251 __uninit_fill_n(__first, __n, __x);
252 }
253
254 // Extensions: versions of uninitialized_copy, uninitialized_fill,
255 // and uninitialized_fill_n that take an allocator parameter.
256 // We dispatch back to the standard versions when we're given the
257 // default allocator. For nondefault allocators we do not use
258 // any of the POD optimizations.
259
260 template<typename _InputIterator, typename _ForwardIterator,
261 typename _Allocator>
262 _ForwardIterator
263 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
264 _ForwardIterator __result, _Allocator& __alloc)
265 {
266 _ForwardIterator __cur = __result;
267 __try
268 {
269 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
270 for (; __first != __last; ++__first, (void)++__cur)
271 __traits::construct(__alloc, std::__addressof(*__cur), *__first);
272 return __cur;
273 }
274 __catch(...)
275 {
276 std::_Destroy(__result, __cur, __alloc);
277 __throw_exception_again;
278 }
279 }
280
281 template<typename _InputIterator, typename _ForwardIterator, typename _Tp>
282 inline _ForwardIterator
283 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
284 _ForwardIterator __result, allocator<_Tp>&)
285 { return std::uninitialized_copy(__first, __last, __result); }
286
287 template<typename _InputIterator, typename _ForwardIterator,
288 typename _Allocator>
289 inline _ForwardIterator
290 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
291 _ForwardIterator __result, _Allocator& __alloc)
292 {
293 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
294 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
295 __result, __alloc);
296 }
297
298 template<typename _InputIterator, typename _ForwardIterator,
299 typename _Allocator>
300 inline _ForwardIterator
301 __uninitialized_move_if_noexcept_a(_InputIterator __first,
302 _InputIterator __last,
303 _ForwardIterator __result,
304 _Allocator& __alloc)
305 {
306 return std::__uninitialized_copy_a
307 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
308 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
309 }
310
311 template<typename _ForwardIterator, typename _Tp, typename _Allocator>
312 void
313 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
314 const _Tp& __x, _Allocator& __alloc)
315 {
316 _ForwardIterator __cur = __first;
317 __try
318 {
319 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
320 for (; __cur != __last; ++__cur)
321 __traits::construct(__alloc, std::__addressof(*__cur), __x);
322 }
323 __catch(...)
324 {
325 std::_Destroy(__first, __cur, __alloc);
326 __throw_exception_again;
327 }
328 }
329
330 template<typename _ForwardIterator, typename _Tp, typename _Tp2>
331 inline void
332 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
333 const _Tp& __x, allocator<_Tp2>&)
334 { std::uninitialized_fill(__first, __last, __x); }
335
336 template<typename _ForwardIterator, typename _Size, typename _Tp,
337 typename _Allocator>
338 _ForwardIterator
339 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
340 const _Tp& __x, _Allocator& __alloc)
341 {
342 _ForwardIterator __cur = __first;
343 __try
344 {
345 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
346 for (; __n > 0; --__n, ++__cur)
347 __traits::construct(__alloc, std::__addressof(*__cur), __x);
348 return __cur;
349 }
350 __catch(...)
351 {
352 std::_Destroy(__first, __cur, __alloc);
353 __throw_exception_again;
354 }
355 }
356
357 template<typename _ForwardIterator, typename _Size, typename _Tp,
358 typename _Tp2>
359 inline _ForwardIterator
360 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
361 const _Tp& __x, allocator<_Tp2>&)
362 { return std::uninitialized_fill_n(__first, __n, __x); }
363
364
365 // Extensions: __uninitialized_copy_move, __uninitialized_move_copy,
366 // __uninitialized_fill_move, __uninitialized_move_fill.
367 // All of these algorithms take a user-supplied allocator, which is used
368 // for construction and destruction.
369
370 // __uninitialized_copy_move
371 // Copies [first1, last1) into [result, result + (last1 - first1)), and
372 // move [first2, last2) into
373 // [result, result + (last1 - first1) + (last2 - first2)).
374 template<typename _InputIterator1, typename _InputIterator2,
375 typename _ForwardIterator, typename _Allocator>
376 inline _ForwardIterator
377 __uninitialized_copy_move(_InputIterator1 __first1,
378 _InputIterator1 __last1,
379 _InputIterator2 __first2,
380 _InputIterator2 __last2,
381 _ForwardIterator __result,
382 _Allocator& __alloc)
383 {
384 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
385 __result,
386 __alloc);
387 __try
388 {
389 return std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
390 }
391 __catch(...)
392 {
393 std::_Destroy(__result, __mid, __alloc);
394 __throw_exception_again;
395 }
396 }
397
398 // __uninitialized_move_copy
399 // Moves [first1, last1) into [result, result + (last1 - first1)), and
400 // copies [first2, last2) into
401 // [result, result + (last1 - first1) + (last2 - first2)).
402 template<typename _InputIterator1, typename _InputIterator2,
403 typename _ForwardIterator, typename _Allocator>
404 inline _ForwardIterator
405 __uninitialized_move_copy(_InputIterator1 __first1,
406 _InputIterator1 __last1,
407 _InputIterator2 __first2,
408 _InputIterator2 __last2,
409 _ForwardIterator __result,
410 _Allocator& __alloc)
411 {
412 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
413 __result,
414 __alloc);
415 __try
416 {
417 return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
418 }
419 __catch(...)
420 {
421 std::_Destroy(__result, __mid, __alloc);
422 __throw_exception_again;
423 }
424 }
425
426 // __uninitialized_fill_move
427 // Fills [result, mid) with x, and moves [first, last) into
428 // [mid, mid + (last - first)).
429 template<typename _ForwardIterator, typename _Tp, typename _InputIterator,
430 typename _Allocator>
431 inline _ForwardIterator
432 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
433 const _Tp& __x, _InputIterator __first,
434 _InputIterator __last, _Allocator& __alloc)
435 {
436 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
437 __try
438 {
439 return std::__uninitialized_move_a(__first, __last, __mid, __alloc);
440 }
441 __catch(...)
442 {
443 std::_Destroy(__result, __mid, __alloc);
444 __throw_exception_again;
445 }
446 }
447
448 // __uninitialized_move_fill
449 // Moves [first1, last1) into [first2, first2 + (last1 - first1)), and
450 // fills [first2 + (last1 - first1), last2) with x.
451 template<typename _InputIterator, typename _ForwardIterator, typename _Tp,
452 typename _Allocator>
453 inline void
454 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
455 _ForwardIterator __first2,
456 _ForwardIterator __last2, const _Tp& __x,
457 _Allocator& __alloc)
458 {
459 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
460 __first2,
461 __alloc);
462 __try
463 {
464 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
465 }
466 __catch(...)
467 {
468 std::_Destroy(__first2, __mid2, __alloc);
469 __throw_exception_again;
470 }
471 }
472
473 #if __cplusplus >= 201103L
474 // Extensions: __uninitialized_default, __uninitialized_default_n,
475 // __uninitialized_default_a, __uninitialized_default_n_a.
476
477 template<bool _TrivialValueType>
478 struct __uninitialized_default_1
479 {
480 template<typename _ForwardIterator>
481 static void
482 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
483 {
484 _ForwardIterator __cur = __first;
485 __try
486 {
487 for (; __cur != __last; ++__cur)
488 std::_Construct(std::__addressof(*__cur));
489 }
490 __catch(...)
491 {
492 std::_Destroy(__first, __cur);
493 __throw_exception_again;
494 }
495 }
496 };
497
498 template<>
499 struct __uninitialized_default_1<true>
500 {
501 template<typename _ForwardIterator>
502 static void
503 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
504 {
505 typedef typename iterator_traits<_ForwardIterator>::value_type
506 _ValueType;
507
508 std::fill(__first, __last, _ValueType());
509 }
510 };
511
512 template<bool _TrivialValueType>
513 struct __uninitialized_default_n_1
514 {
515 template<typename _ForwardIterator, typename _Size>
516 static _ForwardIterator
517 __uninit_default_n(_ForwardIterator __first, _Size __n)
518 {
519 _ForwardIterator __cur = __first;
520 __try
521 {
522 for (; __n > 0; --__n, ++__cur)
523 std::_Construct(std::__addressof(*__cur));
524 return __cur;
525 }
526 __catch(...)
527 {
528 std::_Destroy(__first, __cur);
529 __throw_exception_again;
530 }
531 }
532 };
533
534 template<>
535 struct __uninitialized_default_n_1<true>
536 {
537 template<typename _ForwardIterator, typename _Size>
538 static _ForwardIterator
539 __uninit_default_n(_ForwardIterator __first, _Size __n)
540 {
541 typedef typename iterator_traits<_ForwardIterator>::value_type
542 _ValueType;
543
544 return std::fill_n(__first, __n, _ValueType());
545 }
546 };
547
548 // __uninitialized_default
549 // Fills [first, last) with std::distance(first, last) default
550 // constructed value_types(s).
551 template<typename _ForwardIterator>
552 inline void
553 __uninitialized_default(_ForwardIterator __first,
554 _ForwardIterator __last)
555 {
556 typedef typename iterator_traits<_ForwardIterator>::value_type
557 _ValueType;
558 // trivial types can have deleted assignment
559 const bool __assignable = is_copy_assignable<_ValueType>::value;
560
561 std::__uninitialized_default_1<__is_trivial(_ValueType)
562 && __assignable>::
563 __uninit_default(__first, __last);
564 }
565
566 // __uninitialized_default_n
567 // Fills [first, first + n) with n default constructed value_type(s).
568 template<typename _ForwardIterator, typename _Size>
569 inline _ForwardIterator
570 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
571 {
572 typedef typename iterator_traits<_ForwardIterator>::value_type
573 _ValueType;
574 // trivial types can have deleted assignment
575 const bool __assignable = is_copy_assignable<_ValueType>::value;
576
577 return __uninitialized_default_n_1<__is_trivial(_ValueType)
578 && __assignable>::
579 __uninit_default_n(__first, __n);
580 }
581
582
583 // __uninitialized_default_a
584 // Fills [first, last) with std::distance(first, last) default
585 // constructed value_types(s), constructed with the allocator alloc.
586 template<typename _ForwardIterator, typename _Allocator>
587 void
588 __uninitialized_default_a(_ForwardIterator __first,
589 _ForwardIterator __last,
590 _Allocator& __alloc)
591 {
592 _ForwardIterator __cur = __first;
593 __try
594 {
595 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
596 for (; __cur != __last; ++__cur)
597 __traits::construct(__alloc, std::__addressof(*__cur));
598 }
599 __catch(...)
600 {
601 std::_Destroy(__first, __cur, __alloc);
602 __throw_exception_again;
603 }
604 }
605
606 template<typename _ForwardIterator, typename _Tp>
607 inline void
608 __uninitialized_default_a(_ForwardIterator __first,
609 _ForwardIterator __last,
610 allocator<_Tp>&)
611 { std::__uninitialized_default(__first, __last); }
612
613
614 // __uninitialized_default_n_a
615 // Fills [first, first + n) with n default constructed value_types(s),
616 // constructed with the allocator alloc.
617 template<typename _ForwardIterator, typename _Size, typename _Allocator>
618 _ForwardIterator
619 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
620 _Allocator& __alloc)
621 {
622 _ForwardIterator __cur = __first;
623 __try
624 {
625 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
626 for (; __n > 0; --__n, ++__cur)
627 __traits::construct(__alloc, std::__addressof(*__cur));
628 return __cur;
629 }
630 __catch(...)
631 {
632 std::_Destroy(__first, __cur, __alloc);
633 __throw_exception_again;
634 }
635 }
636
637 template<typename _ForwardIterator, typename _Size, typename _Tp>
638 inline _ForwardIterator
639 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
640 allocator<_Tp>&)
641 { return std::__uninitialized_default_n(__first, __n); }
642
643
644 template<typename _InputIterator, typename _Size,
645 typename _ForwardIterator>
646 _ForwardIterator
647 __uninitialized_copy_n(_InputIterator __first, _Size __n,
648 _ForwardIterator __result, input_iterator_tag)
649 {
650 _ForwardIterator __cur = __result;
651 __try
652 {
653 for (; __n > 0; --__n, ++__first, ++__cur)
654 std::_Construct(std::__addressof(*__cur), *__first);
655 return __cur;
656 }
657 __catch(...)
658 {
659 std::_Destroy(__result, __cur);
660 __throw_exception_again;
661 }
662 }
663
664 template<typename _RandomAccessIterator, typename _Size,
665 typename _ForwardIterator>
666 inline _ForwardIterator
667 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
668 _ForwardIterator __result,
669 random_access_iterator_tag)
670 { return std::uninitialized_copy(__first, __first + __n, __result); }
671
672 /**
673 * @brief Copies the range [first,first+n) into result.
674 * @param __first An input iterator.
675 * @param __n The number of elements to copy.
676 * @param __result An output iterator.
677 * @return __result + __n
678 *
679 * Like copy_n(), but does not require an initialized output range.
680 */
681 template<typename _InputIterator, typename _Size, typename _ForwardIterator>
682 inline _ForwardIterator
683 uninitialized_copy_n(_InputIterator __first, _Size __n,
684 _ForwardIterator __result)
685 { return std::__uninitialized_copy_n(__first, __n, __result,
686 std::__iterator_category(__first)); }
687 #endif
688
689 #if __cplusplus > 201402L
690 template <typename _ForwardIterator>
691 inline void
692 uninitialized_default_construct(_ForwardIterator __first,
693 _ForwardIterator __last)
694 {
695 for (; __first != __last; ++__first)
696 ::new (static_cast<void*>(std::__addressof(*__first)))
697 typename iterator_traits<_ForwardIterator>::value_type;
698 }
699
700 template <typename _ForwardIterator, typename _Size>
701 inline _ForwardIterator
702 uninitialized_default_construct_n(_ForwardIterator __first, _Size __count)
703 {
704 for (; __count > 0; (void)++__first, --__count)
705 ::new (static_cast<void*>(std::__addressof(*__first)))
706 typename iterator_traits<_ForwardIterator>::value_type;
707 return __first;
708 }
709
710 template <typename _ForwardIterator>
711 inline void
712 uninitialized_value_construct(_ForwardIterator __first,
713 _ForwardIterator __last)
714 {
715 for (; __first != __last; ++__first)
716 ::new (static_cast<void*>(std::__addressof(*__first)))
717 typename iterator_traits<_ForwardIterator>::value_type();
718 }
719
720 template <typename _ForwardIterator, typename _Size>
721 inline _ForwardIterator
722 uninitialized_value_construct_n(_ForwardIterator __first, _Size __count)
723 {
724 for (; __count > 0; (void)++__first, --__count)
725 ::new (static_cast<void*>(std::__addressof(*__first)))
726 typename iterator_traits<_ForwardIterator>::value_type();
727 return __first;
728 }
729
730 template <typename _InputIterator, typename _ForwardIterator>
731 inline _ForwardIterator
732 uninitialized_move(_InputIterator __first, _InputIterator __last,
733 _ForwardIterator __result)
734 {
735 for (; __first != __last; (void)++__result, ++__first)
736 ::new (static_cast<void*>(std::__addressof(*__result)))
737 typename
738 iterator_traits<_ForwardIterator>::value_type(std::move(*__first));
739 return __result;
740 }
741
742 template <typename _InputIterator, typename _Size, typename _ForwardIterator>
743 inline pair<_InputIterator, _ForwardIterator>
744 uninitialized_move_n(_InputIterator __first, _Size __count,
745 _ForwardIterator __result)
746 {
747 for (; __count > 0; ++__result, (void) ++__first, --__count)
748 ::new (static_cast<void*>(std::__addressof(*__result)))
749 typename
750 iterator_traits<_ForwardIterator>::value_type(std::move(*__first));
751 return {__first, __result};
752 }
753
754 template <typename _Tp>
755 inline void
756 destroy_at(_Tp* __location)
757 {
758 __location->~_Tp();
759 }
760
761 template <typename _ForwardIterator>
762 inline void
763 destroy(_ForwardIterator __first, _ForwardIterator __last)
764 {
765 for (; __first != __last; ++__first)
766 std::destroy_at(std::__addressof(*__first));
767 }
768
769 template <typename _ForwardIterator, typename _Size>
770 inline _ForwardIterator
771 destroy_n(_ForwardIterator __first, _Size __count)
772 {
773 for (; __count > 0; (void)++__first, --__count)
774 std::destroy_at(std::__addressof(*__first));
775 return __first;
776 }
777
778 #endif
779
780
781 _GLIBCXX_END_NAMESPACE_VERSION
782 } // namespace
783
784 #endif /* _STL_UNINITIALIZED_H */