56 #ifndef _STL_UNINITIALIZED_H
57 #define _STL_UNINITIALIZED_H 1
59 #if __cplusplus > 201402L
63 #if __cplusplus >= 201103L
69 namespace std _GLIBCXX_VISIBILITY(default)
71 _GLIBCXX_BEGIN_NAMESPACE_VERSION
79 template<
bool _TrivialValueTypes>
80 struct __uninitialized_copy
82 template<
typename _InputIterator,
typename _ForwardIterator>
83 static _ForwardIterator
84 __uninit_copy(_InputIterator __first, _InputIterator __last,
85 _ForwardIterator __result)
87 _ForwardIterator __cur = __result;
90 for (; __first != __last; ++__first, (void)++__cur)
97 __throw_exception_again;
103 struct __uninitialized_copy<true>
105 template<
typename _InputIterator,
typename _ForwardIterator>
106 static _ForwardIterator
107 __uninit_copy(_InputIterator __first, _InputIterator __last,
108 _ForwardIterator __result)
109 {
return std::copy(__first, __last, __result); }
123 template<
typename _InputIterator,
typename _ForwardIterator>
124 inline _ForwardIterator
126 _ForwardIterator __result)
132 #if __cplusplus < 201103L
133 const bool __assignable =
true;
138 "result type must be constructible from value type of input range");
147 return std::__uninitialized_copy<__is_trivial(_ValueType1)
148 && __is_trivial(_ValueType2)
150 __uninit_copy(__first, __last, __result);
155 template<
bool _TrivialValueType>
156 struct __uninitialized_fill
158 template<
typename _ForwardIterator,
typename _Tp>
160 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
163 _ForwardIterator __cur = __first;
166 for (; __cur != __last; ++__cur)
172 __throw_exception_again;
178 struct __uninitialized_fill<true>
180 template<
typename _ForwardIterator,
typename _Tp>
182 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
198 template<
typename _ForwardIterator,
typename _Tp>
205 #if __cplusplus < 201103L
206 const bool __assignable =
true;
211 "result type must be constructible from input type");
218 std::__uninitialized_fill<__is_trivial(_ValueType) && __assignable>::
219 __uninit_fill(__first, __last, __x);
224 template<
bool _TrivialValueType>
225 struct __uninitialized_fill_n
227 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
228 static _ForwardIterator
229 __uninit_fill_n(_ForwardIterator __first, _Size __n,
232 _ForwardIterator __cur = __first;
235 for (; __n > 0; --__n, (void) ++__cur)
242 __throw_exception_again;
248 struct __uninitialized_fill_n<true>
250 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
251 static _ForwardIterator
252 __uninit_fill_n(_ForwardIterator __first, _Size __n,
270 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
271 inline _ForwardIterator
282 #if __cplusplus < 201103L
283 const bool __can_fill = __is_integer<_Size>::__value;
288 "result type must be constructible from input type");
292 constexpr
bool __can_fill
295 return __uninitialized_fill_n<__is_trivial(_ValueType) && __can_fill>::
296 __uninit_fill_n(__first, __n, __x);
307 template<
typename _InputIterator,
typename _ForwardIterator,
310 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
311 _ForwardIterator __result, _Allocator& __alloc)
313 _ForwardIterator __cur = __result;
317 for (; __first != __last; ++__first, (void)++__cur)
324 __throw_exception_again;
328 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp>
329 inline _ForwardIterator
330 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
331 _ForwardIterator __result, allocator<_Tp>&)
334 template<
typename _InputIterator,
typename _ForwardIterator,
336 inline _ForwardIterator
337 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
338 _ForwardIterator __result, _Allocator& __alloc)
340 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
341 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
345 template<
typename _InputIterator,
typename _ForwardIterator,
347 inline _ForwardIterator
348 __uninitialized_move_if_noexcept_a(_InputIterator __first,
349 _InputIterator __last,
350 _ForwardIterator __result,
353 return std::__uninitialized_copy_a
354 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
355 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
358 template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
360 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
361 const _Tp& __x, _Allocator& __alloc)
363 _ForwardIterator __cur = __first;
367 for (; __cur != __last; ++__cur)
373 __throw_exception_again;
377 template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
379 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
380 const _Tp& __x, allocator<_Tp2>&)
383 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
386 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
387 const _Tp& __x, _Allocator& __alloc)
389 _ForwardIterator __cur = __first;
393 for (; __n > 0; --__n, (void) ++__cur)
400 __throw_exception_again;
404 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
406 inline _ForwardIterator
407 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
408 const _Tp& __x, allocator<_Tp2>&)
421 template<
typename _InputIterator1,
typename _InputIterator2,
422 typename _ForwardIterator,
typename _Allocator>
423 inline _ForwardIterator
424 __uninitialized_copy_move(_InputIterator1 __first1,
425 _InputIterator1 __last1,
426 _InputIterator2 __first2,
427 _InputIterator2 __last2,
428 _ForwardIterator __result,
431 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
436 return std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
441 __throw_exception_again;
449 template<
typename _InputIterator1,
typename _InputIterator2,
450 typename _ForwardIterator,
typename _Allocator>
451 inline _ForwardIterator
452 __uninitialized_move_copy(_InputIterator1 __first1,
453 _InputIterator1 __last1,
454 _InputIterator2 __first2,
455 _InputIterator2 __last2,
456 _ForwardIterator __result,
459 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
464 return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
469 __throw_exception_again;
476 template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
478 inline _ForwardIterator
479 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
480 const _Tp& __x, _InputIterator __first,
481 _InputIterator __last, _Allocator& __alloc)
483 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
486 return std::__uninitialized_move_a(__first, __last, __mid, __alloc);
491 __throw_exception_again;
498 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
501 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
502 _ForwardIterator __first2,
503 _ForwardIterator __last2,
const _Tp& __x,
506 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
511 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
516 __throw_exception_again;
522 #if __cplusplus >= 201103L
528 template<
bool _TrivialValueType>
529 struct __uninitialized_default_1
531 template<
typename _ForwardIterator>
533 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
535 _ForwardIterator __cur = __first;
538 for (; __cur != __last; ++__cur)
544 __throw_exception_again;
550 struct __uninitialized_default_1<true>
552 template<
typename _ForwardIterator>
554 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
556 if (__first == __last)
559 typename iterator_traits<_ForwardIterator>::value_type* __val
562 if (++__first != __last)
567 template<
bool _TrivialValueType>
568 struct __uninitialized_default_n_1
570 template<
typename _ForwardIterator,
typename _Size>
571 static _ForwardIterator
572 __uninit_default_n(_ForwardIterator __first, _Size __n)
574 _ForwardIterator __cur = __first;
577 for (; __n > 0; --__n, (void) ++__cur)
584 __throw_exception_again;
590 struct __uninitialized_default_n_1<true>
592 template<
typename _ForwardIterator,
typename _Size>
593 static _ForwardIterator
594 __uninit_default_n(_ForwardIterator __first, _Size __n)
598 typename iterator_traits<_ForwardIterator>::value_type* __val
610 template<
typename _ForwardIterator>
612 __uninitialized_default(_ForwardIterator __first,
613 _ForwardIterator __last)
615 typedef typename iterator_traits<_ForwardIterator>::value_type
618 const bool __assignable = is_copy_assignable<_ValueType>::value;
620 std::__uninitialized_default_1<__is_trivial(_ValueType)
622 __uninit_default(__first, __last);
627 template<
typename _ForwardIterator,
typename _Size>
628 inline _ForwardIterator
629 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
631 typedef typename iterator_traits<_ForwardIterator>::value_type
634 constexpr
bool __can_fill
635 = __and_<is_integral<_Size>, is_copy_assignable<_ValueType>>::value;
637 return __uninitialized_default_n_1<__is_trivial(_ValueType)
639 __uninit_default_n(__first, __n);
646 template<
typename _ForwardIterator,
typename _Allocator>
648 __uninitialized_default_a(_ForwardIterator __first,
649 _ForwardIterator __last,
652 _ForwardIterator __cur = __first;
656 for (; __cur != __last; ++__cur)
662 __throw_exception_again;
666 template<
typename _ForwardIterator,
typename _Tp>
668 __uninitialized_default_a(_ForwardIterator __first,
669 _ForwardIterator __last,
671 { std::__uninitialized_default(__first, __last); }
677 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
679 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
682 _ForwardIterator __cur = __first;
686 for (; __n > 0; --__n, (void) ++__cur)
693 __throw_exception_again;
699 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
700 inline _ForwardIterator
701 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
703 {
return std::__uninitialized_default_n(__first, __n); }
705 template<
bool _TrivialValueType>
706 struct __uninitialized_default_novalue_1
708 template<
typename _ForwardIterator>
710 __uninit_default_novalue(_ForwardIterator __first,
711 _ForwardIterator __last)
713 _ForwardIterator __cur = __first;
716 for (; __cur != __last; ++__cur)
722 __throw_exception_again;
728 struct __uninitialized_default_novalue_1<true>
730 template<
typename _ForwardIterator>
732 __uninit_default_novalue(_ForwardIterator __first,
733 _ForwardIterator __last)
738 template<
bool _TrivialValueType>
739 struct __uninitialized_default_novalue_n_1
741 template<
typename _ForwardIterator,
typename _Size>
742 static _ForwardIterator
743 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
745 _ForwardIterator __cur = __first;
748 for (; __n > 0; --__n, (void) ++__cur)
755 __throw_exception_again;
761 struct __uninitialized_default_novalue_n_1<true>
763 template<
typename _ForwardIterator,
typename _Size>
764 static _ForwardIterator
765 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
766 {
return std::next(__first, __n); }
771 template<
typename _ForwardIterator>
773 __uninitialized_default_novalue(_ForwardIterator __first,
774 _ForwardIterator __last)
776 typedef typename iterator_traits<_ForwardIterator>::value_type
779 std::__uninitialized_default_novalue_1<
780 is_trivially_default_constructible<_ValueType>::value>::
781 __uninit_default_novalue(__first, __last);
786 template<
typename _ForwardIterator,
typename _Size>
787 inline _ForwardIterator
788 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
790 typedef typename iterator_traits<_ForwardIterator>::value_type
793 return __uninitialized_default_novalue_n_1<
794 is_trivially_default_constructible<_ValueType>::value>::
795 __uninit_default_novalue_n(__first, __n);
798 template<
typename _InputIterator,
typename _Size,
799 typename _ForwardIterator>
801 __uninitialized_copy_n(_InputIterator __first, _Size __n,
802 _ForwardIterator __result, input_iterator_tag)
804 _ForwardIterator __cur = __result;
807 for (; __n > 0; --__n, (void) ++__first, ++__cur)
814 __throw_exception_again;
818 template<
typename _RandomAccessIterator,
typename _Size,
819 typename _ForwardIterator>
820 inline _ForwardIterator
821 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
822 _ForwardIterator __result,
823 random_access_iterator_tag)
826 template<
typename _InputIterator,
typename _Size,
827 typename _ForwardIterator>
828 pair<_InputIterator, _ForwardIterator>
829 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
830 _ForwardIterator __result, input_iterator_tag)
832 _ForwardIterator __cur = __result;
835 for (; __n > 0; --__n, (void) ++__first, ++__cur)
837 return {__first, __cur};
842 __throw_exception_again;
846 template<
typename _RandomAccessIterator,
typename _Size,
847 typename _ForwardIterator>
848 inline pair<_RandomAccessIterator, _ForwardIterator>
849 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
850 _ForwardIterator __result,
851 random_access_iterator_tag)
854 auto __first_res = std::next(__first, __n);
855 return {__first_res, __second_res};
869 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
870 inline _ForwardIterator
872 _ForwardIterator __result)
873 {
return std::__uninitialized_copy_n(__first, __n, __result,
877 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
878 inline pair<_InputIterator, _ForwardIterator>
879 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
880 _ForwardIterator __result)
883 std::__uninitialized_copy_n_pair(__first, __n, __result,
889 #if __cplusplus >= 201703L
890 # define __cpp_lib_raw_memory_algorithms 201606L
897 template <
typename _ForwardIterator>
900 _ForwardIterator __last)
902 __uninitialized_default_novalue(__first, __last);
911 template <
typename _ForwardIterator,
typename _Size>
912 inline _ForwardIterator
915 return __uninitialized_default_novalue_n(__first, __count);
923 template <
typename _ForwardIterator>
926 _ForwardIterator __last)
928 return __uninitialized_default(__first, __last);
937 template <
typename _ForwardIterator,
typename _Size>
938 inline _ForwardIterator
941 return __uninitialized_default_n(__first, __count);
951 template <
typename _InputIterator,
typename _ForwardIterator>
952 inline _ForwardIterator
954 _ForwardIterator __result)
957 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
958 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
968 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
969 inline pair<_InputIterator, _ForwardIterator>
971 _ForwardIterator __result)
973 auto __res = std::__uninitialized_copy_n_pair
974 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
976 return {__res.first.base(), __res.second};
980 #if __cplusplus >= 201103L
983 template<
typename _Tp,
typename _Up,
typename _Allocator>
985 __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig,
993 __traits::construct(__alloc, __dest,
std::move(*__orig));
999 template<
typename _Tp,
typename =
void>
1000 struct __is_bitwise_relocatable
1001 : is_trivial<_Tp> { };
1003 template <
typename _Tp,
typename _Up>
1004 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
1005 __relocate_a_1(_Tp* __first, _Tp* __last,
1006 _Tp* __result, allocator<_Up>&) noexcept
1008 ptrdiff_t __count = __last - __first;
1010 __builtin_memmove(__result, __first, __count *
sizeof(_Tp));
1011 return __result + __count;
1014 template <
typename _InputIterator,
typename _ForwardIterator,
1015 typename _Allocator>
1016 inline _ForwardIterator
1017 __relocate_a_1(_InputIterator __first, _InputIterator __last,
1018 _ForwardIterator __result, _Allocator& __alloc)
1019 noexcept(noexcept(std::__relocate_object_a(
std::addressof(*__result),
1023 typedef typename iterator_traits<_InputIterator>::value_type
1025 typedef typename iterator_traits<_ForwardIterator>::value_type
1028 "relocation is only possible for values of the same type");
1029 _ForwardIterator __cur = __result;
1030 for (; __first != __last; ++__first, (void)++__cur)
1036 template <
typename _InputIterator,
typename _ForwardIterator,
1037 typename _Allocator>
1038 inline _ForwardIterator
1039 __relocate_a(_InputIterator __first, _InputIterator __last,
1040 _ForwardIterator __result, _Allocator& __alloc)
1041 noexcept(noexcept(__relocate_a_1(std::__niter_base(__first),
1042 std::__niter_base(__last),
1043 std::__niter_base(__result), __alloc)))
1045 return __relocate_a_1(std::__niter_base(__first),
1046 std::__niter_base(__last),
1047 std::__niter_base(__result), __alloc);
1055 _GLIBCXX_END_NAMESPACE_VERSION