56#ifndef _STL_UNINITIALIZED_H
57#define _STL_UNINITIALIZED_H 1
59#if __cplusplus >= 201103L
71namespace std _GLIBCXX_VISIBILITY(default)
73_GLIBCXX_BEGIN_NAMESPACE_VERSION
81 template<
typename _ForwardIterator,
typename _Alloc =
void>
82 struct _UninitDestroyGuard
86 _UninitDestroyGuard(_ForwardIterator& __first, _Alloc& __a)
87 : _M_first(__first), _M_cur(__builtin_addressof(__first)), _M_alloc(__a)
91 ~_UninitDestroyGuard()
93 if (__builtin_expect(_M_cur != 0, 0))
98 void release() { _M_cur = 0; }
101 _ForwardIterator
const _M_first;
102 _ForwardIterator* _M_cur;
105 _UninitDestroyGuard(
const _UninitDestroyGuard&);
108 template<
typename _ForwardIterator>
109 struct _UninitDestroyGuard<_ForwardIterator, void>
113 _UninitDestroyGuard(_ForwardIterator& __first)
114 : _M_first(__first), _M_cur(__builtin_addressof(__first))
118 ~_UninitDestroyGuard()
120 if (__builtin_expect(_M_cur != 0, 0))
125 void release() { _M_cur = 0; }
127 _ForwardIterator
const _M_first;
128 _ForwardIterator* _M_cur;
131 _UninitDestroyGuard(
const _UninitDestroyGuard&);
136 template<
typename _InputIterator,
typename _Sentinel,
137 typename _ForwardIterator>
140 __do_uninit_copy(_InputIterator __first, _Sentinel __last,
141 _ForwardIterator __result)
143 _UninitDestroyGuard<_ForwardIterator> __guard(__result);
144 for (; __first != __last; ++__first, (void)++__result)
150#if __cplusplus < 201103L
153 template<
typename _Iter,
154 typename _Base = __decltype(std::__niter_base(*(_Iter*)0))>
155 struct __unwrappable_niter
156 {
enum { __value =
false }; };
158 template<
typename _Iter,
typename _Tp>
159 struct __unwrappable_niter<_Iter, _Tp*>
160 {
enum { __value =
true }; };
163 template<
bool _CanMemcpy>
164 struct __uninitialized_copy
166 template<
typename _InputIterator,
typename _ForwardIterator>
167 static _ForwardIterator
168 __uninit_copy(_InputIterator __first, _InputIterator __last,
169 _ForwardIterator __result)
170 {
return std::__do_uninit_copy(__first, __last, __result); }
174 struct __uninitialized_copy<true>
177 template<
typename _InputIterator,
typename _ForwardIterator>
178 static _ForwardIterator
179 __uninit_copy(_InputIterator __first, _InputIterator __last,
180 _ForwardIterator __result)
182 if (__unwrappable_niter<_InputIterator>::__value
183 && __unwrappable_niter<_ForwardIterator>::__value)
185 __uninit_copy(std::__niter_base(__first),
186 std::__niter_base(__last),
187 std::__niter_base(__result));
192 return std::__do_uninit_copy(__first, __last, __result);
196 template<
typename _Tp,
typename _Up>
198 __uninit_copy(_Tp* __first, _Tp* __last, _Up* __result)
202 typedef __typeof__(
static_cast<_Up
>(*__first)) __check
203 __attribute__((__unused__));
205 const ptrdiff_t __n = __last - __first;
206 if (__builtin_expect(__n > 0,
true))
208 __builtin_memcpy(__result, __first, __n *
sizeof(_Tp));
217#pragma GCC diagnostic push
218#pragma GCC diagnostic ignored "-Wc++17-extensions"
228 template<
typename _InputIterator,
typename _ForwardIterator>
230 inline _ForwardIterator
232 _ForwardIterator __result)
255#if __cplusplus >= 201103L
256 using _Dest =
decltype(std::__niter_base(__result));
257 using _Src =
decltype(std::__niter_base(__first));
260#if __glibcxx_raw_memory_algorithms >= 202411L
262 return std::__do_uninit_copy(__first, __last, __result);
265 if constexpr (!__is_trivially_constructible(_ValT,
decltype(*__first)))
266 return std::__do_uninit_copy(__first, __last, __result);
267 else if constexpr (__memcpyable<_Dest, _Src>::__value)
269 ptrdiff_t __n = __last - __first;
270 if (__n > 0) [[__likely__]]
272 using _ValT =
typename remove_pointer<_Src>::type;
273 __builtin_memcpy(std::__niter_base(__result),
274 std::__niter_base(__first),
275 __n *
sizeof(_ValT));
280#if __cpp_lib_concepts
281 else if constexpr (contiguous_iterator<_ForwardIterator>
282 && contiguous_iterator<_InputIterator>)
286 if constexpr (__memcpyable<_DestPtr, _SrcPtr>::__value)
288 if (
auto __n = __last - __first; __n > 0) [[likely]]
293 __builtin_memcpy(__dest, __src, __nbytes);
299 return std::__do_uninit_copy(__first, __last, __result);
303 return std::__do_uninit_copy(__first, __last, __result);
310 const bool __can_memcpy
311 = __memcpyable<_ValueType1*, _ValueType2*>::__value
312 && __is_trivially_constructible(_ValueType2, __decltype(*__first));
314 return __uninitialized_copy<__can_memcpy>::
315 __uninit_copy(__first, __last, __result);
318#pragma GCC diagnostic pop
323 template<
typename _ForwardIterator,
typename _Tp>
324 _GLIBCXX20_CONSTEXPR
void
325 __do_uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
328 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
329 for (; __first != __last; ++__first)
334#if __cplusplus < 201103L
336 template<
bool _CanMemset>
337 struct __uninitialized_fill
339 template<
typename _ForwardIterator,
typename _Tp>
341 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
343 { std::__do_uninit_fill(__first, __last, __x); }
347 struct __uninitialized_fill<true>
350 template<
typename _ForwardIterator,
typename _Tp>
352 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
355 if (__unwrappable_niter<_ForwardIterator>::__value)
356 __uninit_fill(std::__niter_base(__first),
357 std::__niter_base(__last),
360 std::__do_uninit_fill(__first, __last, __x);
364 template<
typename _Up,
typename _Tp>
366 __uninit_fill(_Up* __first, _Up* __last,
const _Tp& __x)
370 typedef __typeof__(
static_cast<_Up
>(__x)) __check
371 __attribute__((__unused__));
373 if (__first != __last)
374 __builtin_memset(__first, (
unsigned char)__x, __last - __first);
389 template<
typename _ForwardIterator,
typename _Tp>
407#if __cplusplus >= 201103L
408#pragma GCC diagnostic push
409#pragma GCC diagnostic ignored "-Wc++17-extensions"
410#if __glibcxx_raw_memory_algorithms >= 202411L
412 return std::__do_uninit_fill(__first, __last, __x);
415 if constexpr (__is_byte<_ValueType>::__value)
419 using _BasePtr =
decltype(std::__niter_base(__first));
422 void* __dest = std::__niter_base(__first);
423 ptrdiff_t __n = __last - __first;
424 if (__n > 0) [[__likely__]]
425 __builtin_memset(__dest, (
unsigned char)__x, __n);
428#if __cpp_lib_concepts
429 else if constexpr (contiguous_iterator<_ForwardIterator>)
432 auto __n = __last - __first;
433 if (__n > 0) [[__likely__]]
434 __builtin_memset(__dest, (
unsigned char)__x, __n);
439 std::__do_uninit_fill(__first, __last, __x);
440#pragma GCC diagnostic pop
442 const bool __can_memset = __is_byte<_ValueType>::__value
443 && __is_integer<_Tp>::__value;
445 __uninitialized_fill<__can_memset>::__uninit_fill(__first, __last, __x);
452 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
455 __do_uninit_fill_n(_ForwardIterator __first, _Size __n,
const _Tp& __x)
457 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
458#if __cplusplus >= 201103L
459#pragma GCC diagnostic push
460#pragma GCC diagnostic ignored "-Wc++17-extensions"
461 if constexpr (is_integral<_Size>::value)
463 __glibcxx_assert(__n >= 0);
464 else if constexpr (is_floating_point<_Size>::value)
466 __glibcxx_assert(__n >= 0 &&
static_cast<size_t>(__n) == __n);
467#pragma GCC diagnostic pop
469 for (; __n--; ++__first)
475#if __cplusplus < 201103L
477 template<
bool _CanMemset>
478 struct __uninitialized_fill_n
480 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
481 static _ForwardIterator
482 __uninit_fill_n(_ForwardIterator __first, _Size __n,
484 {
return std::__do_uninit_fill_n(__first, __n, __x); }
488 struct __uninitialized_fill_n<true>
491 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
492 static _ForwardIterator
493 __uninit_fill_n(_ForwardIterator __first, _Size __n,
496 if (__unwrappable_niter<_ForwardIterator>::__value)
498 _ForwardIterator __last = __first;
500 __uninitialized_fill<true>::__uninit_fill(__first, __last, __x);
504 return std::__do_uninit_fill_n(__first, __n, __x);
510#pragma GCC diagnostic push
511#pragma GCC diagnostic ignored "-Wc++17-extensions"
523 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
525 inline _ForwardIterator
537#if __cplusplus >= 201103L
538#if __glibcxx_raw_memory_algorithms >= 202411L
540 return std::__do_uninit_fill_n(__first, __n, __x);
543 if constexpr (__is_byte<_ValueType>::__value)
547 using _BasePtr =
decltype(std::__niter_base(__first));
550 void* __dest = std::__niter_base(__first);
551 if (__n > 0) [[__likely__]]
553 __builtin_memset(__dest, (
unsigned char)__x, __n);
558#if __cpp_lib_concepts
559 else if constexpr (contiguous_iterator<_ForwardIterator>)
562 if (__n > 0) [[__likely__]]
564 __builtin_memset(__dest, (
unsigned char)__x, __n);
571 return std::__do_uninit_fill_n(__first, __n, __x);
573 const bool __can_memset = __is_byte<_ValueType>::__value
574 && __is_integer<_Tp>::__value
575 && __is_integer<_Size>::__value;
577 return __uninitialized_fill_n<__can_memset>::
578 __uninit_fill_n(__first, __n, __x);
581#pragma GCC diagnostic pop
591 template<
typename _InputIterator,
typename _Sentinel,
592 typename _ForwardIterator,
typename _Allocator>
595 __uninitialized_copy_a(_InputIterator __first, _Sentinel __last,
596 _ForwardIterator __result, _Allocator& __alloc)
598 _UninitDestroyGuard<_ForwardIterator, _Allocator>
599 __guard(__result, __alloc);
602 for (; __first != __last; ++__first, (void)++__result)
609 template<
typename _InputIterator,
typename _Sentinel,
610 typename _ForwardIterator,
typename _Tp>
612 inline _ForwardIterator
613 __uninitialized_copy_a(_InputIterator __first, _Sentinel __last,
616#ifdef __cpp_lib_is_constant_evaluated
617 if (std::is_constant_evaluated())
618 return std::__do_uninit_copy(
std::move(__first), __last, __result);
621#ifdef __glibcxx_ranges
622 if constexpr (!is_same_v<_InputIterator, _Sentinel>)
626 if constexpr (sized_sentinel_for<_Sentinel, _InputIterator>
627 && random_access_iterator<_InputIterator>)
629 __first + (__last - __first),
632 return std::__do_uninit_copy(
std::move(__first), __last, __result);
642#if __cplusplus >= 201103L
643 template<
typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp,
645 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
646 __uninitialized_copy_a(
647 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr> __first,
648 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr> __last,
649 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*> __result,
652 template<
typename _Iter,
typename _OTp,
typename _Tp>
653 __enable_if_t<__is_random_access_iter<_Iter>::value,
654 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>>
655 __uninitialized_copy_a(_Iter __first, _Iter __last,
656 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*> __result,
659 template<
typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp,
661 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
662 __uninitialized_move_a(
663 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr> __first,
664 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr> __last,
665 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*> __result,
669 template<
typename _InputIterator,
typename _ForwardIterator,
672 inline _ForwardIterator
673 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
674 _ForwardIterator __result, _Allocator& __alloc)
676 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
677 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
681 template<
typename _InputIterator,
typename _ForwardIterator,
684 inline _ForwardIterator
685 __uninitialized_move_if_noexcept_a(_InputIterator __first,
686 _InputIterator __last,
687 _ForwardIterator __result,
690 return std::__uninitialized_copy_a
691 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
692 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
695 template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
698 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
699 const _Tp& __x, _Allocator& __alloc)
701 _UninitDestroyGuard<_ForwardIterator, _Allocator>
702 __guard(__first, __alloc);
704 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
705 for (; __first != __last; ++__first)
712 template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
715 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
718#ifdef __cpp_lib_is_constant_evaluated
719 if (std::is_constant_evaluated())
720 return std::__do_uninit_fill(__first, __last, __x);
726 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
730 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
731 const _Tp& __x, _Allocator& __alloc)
733 _UninitDestroyGuard<_ForwardIterator, _Allocator>
734 __guard(__first, __alloc);
735 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
736 for (; __n > 0; --__n, (void) ++__first)
743 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
746 inline _ForwardIterator
747 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
750#ifdef __cpp_lib_is_constant_evaluated
751 if (std::is_constant_evaluated())
752 return std::__do_uninit_fill_n(__first, __n, __x);
767 template<
typename _InputIterator1,
typename _InputIterator2,
768 typename _ForwardIterator,
typename _Allocator>
769 inline _ForwardIterator
770 __uninitialized_copy_move(_InputIterator1 __first1,
771 _InputIterator1 __last1,
772 _InputIterator2 __first2,
773 _InputIterator2 __last2,
774 _ForwardIterator __result,
777 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
779 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__result,
782 __result = std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
791 template<
typename _InputIterator1,
typename _InputIterator2,
792 typename _ForwardIterator,
typename _Allocator>
793 inline _ForwardIterator
794 __uninitialized_move_copy(_InputIterator1 __first1,
795 _InputIterator1 __last1,
796 _InputIterator2 __first2,
797 _InputIterator2 __last2,
798 _ForwardIterator __result,
801 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
803 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__result,
806 __result = std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
814 template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
816 inline _ForwardIterator
817 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
818 const _Tp& __x, _InputIterator __first,
819 _InputIterator __last, _Allocator& __alloc)
821 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
822 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__result,
825 __result = std::__uninitialized_move_a(__first, __last, __mid, __alloc);
833 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
836 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
837 _ForwardIterator __first2,
838 _ForwardIterator __last2,
const _Tp& __x,
841 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
844 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__first2,
847 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
853#if __cplusplus >= 201103L
859 template<
bool _TrivialValueType>
860 struct __uninitialized_default_1
862 template<
typename _ForwardIterator>
865 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
867 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
868 for (; __first != __last; ++__first)
875 struct __uninitialized_default_1<true>
877 template<
typename _ForwardIterator>
880 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
882 if (__first == __last)
885 typename iterator_traits<_ForwardIterator>::value_type* __val
888 if (++__first != __last)
889 std::fill(__first, __last, *__val);
893 template<
bool _TrivialValueType>
894 struct __uninitialized_default_n_1
896 template<
typename _ForwardIterator,
typename _Size>
898 static _ForwardIterator
899 __uninit_default_n(_ForwardIterator __first, _Size __n)
901 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
902 for (; __n > 0; --__n, (void) ++__first)
910 struct __uninitialized_default_n_1<true>
912 template<
typename _ForwardIterator,
typename _Size>
914 static _ForwardIterator
915 __uninit_default_n(_ForwardIterator __first, _Size __n)
919 typename iterator_traits<_ForwardIterator>::value_type* __val
923 __first = std::fill_n(__first, __n - 1, *__val);
931 template<
typename _ForwardIterator>
934 __uninitialized_default(_ForwardIterator __first,
935 _ForwardIterator __last)
937#ifdef __cpp_lib_is_constant_evaluated
938 if (std::is_constant_evaluated())
939 return __uninitialized_default_1<false>::
940 __uninit_default(__first, __last);
948 std::__uninitialized_default_1<__is_trivial(_ValueType)
950 __uninit_default(__first, __last);
955 template<
typename _ForwardIterator,
typename _Size>
957 inline _ForwardIterator
958 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
960#ifdef __cpp_lib_is_constant_evaluated
961 if (std::is_constant_evaluated())
962 return __uninitialized_default_n_1<false>::
963 __uninit_default_n(__first, __n);
969 constexpr bool __can_fill
972 return __uninitialized_default_n_1<__is_trivial(_ValueType)
974 __uninit_default_n(__first, __n);
981 template<
typename _ForwardIterator,
typename _Allocator>
983 __uninitialized_default_a(_ForwardIterator __first,
984 _ForwardIterator __last,
987 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__first,
989 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
990 for (; __first != __last; ++__first)
996 template<
typename _ForwardIterator,
typename _Tp>
998 __uninitialized_default_a(_ForwardIterator __first,
999 _ForwardIterator __last,
1001 { std::__uninitialized_default(__first, __last); }
1007 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
1008 _GLIBCXX20_CONSTEXPR _ForwardIterator
1009 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
1010 _Allocator& __alloc)
1012 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__first,
1014 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
1015 for (; __n > 0; --__n, (void) ++__first)
1024 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
1025 _GLIBCXX20_CONSTEXPR
1026 inline _ForwardIterator
1027 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
1029 {
return std::__uninitialized_default_n(__first, __n); }
1032 template<
bool _TrivialValueType>
1033 struct __uninitialized_default_novalue_1
1035 template<
typename _ForwardIterator>
1036 _GLIBCXX26_CONSTEXPR
1038 __uninit_default_novalue(_ForwardIterator __first,
1039 _ForwardIterator __last)
1041 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
1042 for (; __first != __last; ++__first)
1049 struct __uninitialized_default_novalue_1<true>
1051 template<
typename _ForwardIterator>
1052 _GLIBCXX26_CONSTEXPR
1054 __uninit_default_novalue(_ForwardIterator, _ForwardIterator)
1059 template<
bool _TrivialValueType>
1060 struct __uninitialized_default_novalue_n_1
1062 template<
typename _ForwardIterator,
typename _Size>
1063 _GLIBCXX26_CONSTEXPR
1064 static _ForwardIterator
1065 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
1067 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
1068 for (; __n > 0; --__n, (void) ++__first)
1076 struct __uninitialized_default_novalue_n_1<true>
1078 template<
typename _ForwardIterator,
typename _Size>
1079 _GLIBCXX26_CONSTEXPR
1080 static _ForwardIterator
1081 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
1082 {
return std::next(__first, __n); }
1087 template<
typename _ForwardIterator>
1088 _GLIBCXX26_CONSTEXPR
1090 __uninitialized_default_novalue(_ForwardIterator __first,
1091 _ForwardIterator __last)
1096 std::__uninitialized_default_novalue_1<
1098 __uninit_default_novalue(__first, __last);
1103 template<
typename _ForwardIterator,
typename _Size>
1104 _GLIBCXX26_CONSTEXPR
1105 inline _ForwardIterator
1106 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
1111 return __uninitialized_default_novalue_n_1<
1113 __uninit_default_novalue_n(__first, __n);
1116 template<
typename _InputIterator,
typename _Size,
1117 typename _ForwardIterator>
1118 _GLIBCXX26_CONSTEXPR
1120 __uninitialized_copy_n(_InputIterator __first, _Size __n,
1123 _UninitDestroyGuard<_ForwardIterator> __guard(__result);
1124 for (; __n > 0; --__n, (void) ++__first, ++__result)
1130 template<
typename _RandomAccessIterator,
typename _Size,
1131 typename _ForwardIterator>
1132 _GLIBCXX26_CONSTEXPR
1133 inline _ForwardIterator
1134 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
1135 _ForwardIterator __result,
1139 template<
typename _InputIterator,
typename _Size,
1140 typename _ForwardIterator>
1141 _GLIBCXX26_CONSTEXPR
1143 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
1146 _UninitDestroyGuard<_ForwardIterator> __guard(__result);
1147 for (; __n > 0; --__n, (void) ++__first, ++__result)
1150 return {__first, __result};
1153 template<
typename _RandomAccessIterator,
typename _Size,
1154 typename _ForwardIterator>
1155 _GLIBCXX26_CONSTEXPR
1157 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
1158 _ForwardIterator __result,
1162 auto __first_res = std::next(__first, __n);
1163 return {__first_res, __second_res};
1178 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
1179 _GLIBCXX26_CONSTEXPR
1180 inline _ForwardIterator
1182 _ForwardIterator __result)
1183 {
return std::__uninitialized_copy_n(__first, __n, __result,
1187 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
1188 _GLIBCXX26_CONSTEXPR
1190 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
1191 _ForwardIterator __result)
1194 std::__uninitialized_copy_n_pair(__first, __n, __result,
1200#ifdef __glibcxx_raw_memory_algorithms
1207 template <
typename _ForwardIterator>
1208 _GLIBCXX26_CONSTEXPR
1211 _ForwardIterator __last)
1213 std::__uninitialized_default_novalue(__first, __last);
1223 template <
typename _ForwardIterator,
typename _Size>
1224 _GLIBCXX26_CONSTEXPR
1225 inline _ForwardIterator
1228 return std::__uninitialized_default_novalue_n(__first, __count);
1237 template <
typename _ForwardIterator>
1238 _GLIBCXX26_CONSTEXPR
1241 _ForwardIterator __last)
1243 return std::__uninitialized_default(__first, __last);
1253 template <
typename _ForwardIterator,
typename _Size>
1254 _GLIBCXX26_CONSTEXPR
1255 inline _ForwardIterator
1258 return std::__uninitialized_default_n(__first, __count);
1269 template <
typename _InputIterator,
typename _ForwardIterator>
1270 _GLIBCXX26_CONSTEXPR
1271 inline _ForwardIterator
1273 _ForwardIterator __result)
1276 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1277 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
1288 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
1289 _GLIBCXX26_CONSTEXPR
1292 _ForwardIterator __result)
1294 auto __res = std::__uninitialized_copy_n_pair
1295 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1297 return {__res.first.base(), __res.second};
1301#if __cplusplus >= 201103L
1304 template<
typename _Tp,
typename _Up,
typename _Allocator>
1305 _GLIBCXX20_CONSTEXPR
1307 __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig,
1308 _Allocator& __alloc)
1315 __traits::construct(__alloc, __dest,
std::move(*__orig));
1321 template<
typename _Tp,
typename =
void>
1322 struct __is_bitwise_relocatable
1323 : __bool_constant<__is_trivial(_Tp)>
1326 template <
typename _InputIterator,
typename _ForwardIterator,
1327 typename _Allocator>
1328 _GLIBCXX20_CONSTEXPR
1329 inline _ForwardIterator
1330 __relocate_a_1(_InputIterator __first, _InputIterator __last,
1331 _ForwardIterator __result, _Allocator& __alloc)
1332 noexcept(
noexcept(std::__relocate_object_a(
std::addressof(*__result),
1340 static_assert(std::is_same<_ValueType, _ValueType2>::value,
1341 "relocation is only possible for values of the same type");
1342 _ForwardIterator __cur = __result;
1343 for (; __first != __last; ++__first, (void)++__cur)
1350 template <
typename _Tp,
typename _Up>
1351 _GLIBCXX20_CONSTEXPR
1352 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
1353 __relocate_a_1(_Tp* __first, _Tp* __last,
1357 ptrdiff_t __count = __last - __first;
1360#ifdef __cpp_lib_is_constant_evaluated
1361 if (std::is_constant_evaluated())
1365 __gnu_cxx::__normal_iterator<_Tp*, void> __out(__result);
1366 __out = std::__relocate_a_1(__first, __last, __out, __alloc);
1367 return __out.base();
1370 __builtin_memcpy(__result, __first, __count *
sizeof(_Tp));
1372 return __result + __count;
1376 template <
typename _InputIterator,
typename _ForwardIterator,
1377 typename _Allocator>
1378 _GLIBCXX20_CONSTEXPR
1379 inline _ForwardIterator
1380 __relocate_a(_InputIterator __first, _InputIterator __last,
1381 _ForwardIterator __result, _Allocator& __alloc)
1382 noexcept(
noexcept(__relocate_a_1(std::__niter_base(__first),
1383 std::__niter_base(__last),
1384 std::__niter_base(__result), __alloc)))
1386 return std::__relocate_a_1(std::__niter_base(__first),
1387 std::__niter_base(__last),
1388 std::__niter_base(__result), __alloc);
1396_GLIBCXX_END_NAMESPACE_VERSION
_ForwardIterator uninitialized_copy_n(_InputIterator __first, _Size __n, _ForwardIterator __result)
Copies the range [first,first+n) into result.
void uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__x)
Copies the value x into the range [first,last).
_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __count)
Value-initializes objects in the range [first,first+count).
_ForwardIterator uninitialized_move(_InputIterator __first, _InputIterator __last, _ForwardIterator __result)
Move-construct from the range [first,last) into result.
_ForwardIterator uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp &__x)
Copies the value x into the range [first,first+n).
_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __count)
Default-initializes objects in the range [first,first+count).
void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last)
Default-initializes objects in the range [first,last).
_ForwardIterator uninitialized_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result)
Copies the range [first,last) into result.
void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last)
Value-initializes objects in the range [first,last).
pair< _InputIterator, _ForwardIterator > uninitialized_move_n(_InputIterator __first, _Size __count, _ForwardIterator __result)
Move-construct from the range [first,first+count) into result.
constexpr _Tp * to_address(_Tp *__ptr) noexcept
Obtain address referenced by a pointer to an object.
typename remove_pointer< _Tp >::type remove_pointer_t
Alias template for remove_pointer.
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs are equal iff their members are equal.
constexpr _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr void _Construct(_Tp *__p, _Args &&... __args)
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
constexpr void _Destroy(_ForwardIterator __first, _ForwardIterator __last)
is_trivially_default_constructible
Uniform interface to all allocator types.
static constexpr void construct(_Alloc &__a, _Tp *__p, _Args &&... __args) noexcept(_S_nothrow_construct< _Tp, _Args... >())
Construct an object of type _Tp.
static constexpr void destroy(_Alloc &__a, _Tp *__p) noexcept(_S_nothrow_destroy< _Tp >())
Destroy an object of type _Tp.
The standard allocator, as per C++03 [20.4.1].
Struct holding two objects of arbitrary type.
Random-access iterators support a superset of bidirectional iterator operations.
Traits class for iterators.
Uniform interface to C++98 and C++11 allocators.