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 template<
typename _InputIterator,
typename _ForwardIterator,
645 inline _ForwardIterator
646 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
647 _ForwardIterator __result, _Allocator& __alloc)
649 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
650 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
654 template<
typename _InputIterator,
typename _ForwardIterator,
657 inline _ForwardIterator
658 __uninitialized_move_if_noexcept_a(_InputIterator __first,
659 _InputIterator __last,
660 _ForwardIterator __result,
663 return std::__uninitialized_copy_a
664 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
665 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
668 template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
671 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
672 const _Tp& __x, _Allocator& __alloc)
674 _UninitDestroyGuard<_ForwardIterator, _Allocator>
675 __guard(__first, __alloc);
677 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
678 for (; __first != __last; ++__first)
685 template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
688 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
691#ifdef __cpp_lib_is_constant_evaluated
692 if (std::is_constant_evaluated())
693 return std::__do_uninit_fill(__first, __last, __x);
699 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
703 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
704 const _Tp& __x, _Allocator& __alloc)
706 _UninitDestroyGuard<_ForwardIterator, _Allocator>
707 __guard(__first, __alloc);
708 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
709 for (; __n > 0; --__n, (void) ++__first)
716 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
719 inline _ForwardIterator
720 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
723#ifdef __cpp_lib_is_constant_evaluated
724 if (std::is_constant_evaluated())
725 return std::__do_uninit_fill_n(__first, __n, __x);
740 template<
typename _InputIterator1,
typename _InputIterator2,
741 typename _ForwardIterator,
typename _Allocator>
742 inline _ForwardIterator
743 __uninitialized_copy_move(_InputIterator1 __first1,
744 _InputIterator1 __last1,
745 _InputIterator2 __first2,
746 _InputIterator2 __last2,
747 _ForwardIterator __result,
750 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
752 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__result,
755 __result = std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
764 template<
typename _InputIterator1,
typename _InputIterator2,
765 typename _ForwardIterator,
typename _Allocator>
766 inline _ForwardIterator
767 __uninitialized_move_copy(_InputIterator1 __first1,
768 _InputIterator1 __last1,
769 _InputIterator2 __first2,
770 _InputIterator2 __last2,
771 _ForwardIterator __result,
774 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
776 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__result,
779 __result = std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
787 template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
789 inline _ForwardIterator
790 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
791 const _Tp& __x, _InputIterator __first,
792 _InputIterator __last, _Allocator& __alloc)
794 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
795 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__result,
798 __result = std::__uninitialized_move_a(__first, __last, __mid, __alloc);
806 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
809 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
810 _ForwardIterator __first2,
811 _ForwardIterator __last2,
const _Tp& __x,
814 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
817 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__first2,
820 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
826#if __cplusplus >= 201103L
832 template<
bool _TrivialValueType>
833 struct __uninitialized_default_1
835 template<
typename _ForwardIterator>
838 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
840 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
841 for (; __first != __last; ++__first)
848 struct __uninitialized_default_1<true>
850 template<
typename _ForwardIterator>
853 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
855 if (__first == __last)
858 typename iterator_traits<_ForwardIterator>::value_type* __val
861 if (++__first != __last)
862 std::fill(__first, __last, *__val);
866 template<
bool _TrivialValueType>
867 struct __uninitialized_default_n_1
869 template<
typename _ForwardIterator,
typename _Size>
871 static _ForwardIterator
872 __uninit_default_n(_ForwardIterator __first, _Size __n)
874 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
875 for (; __n > 0; --__n, (void) ++__first)
883 struct __uninitialized_default_n_1<true>
885 template<
typename _ForwardIterator,
typename _Size>
887 static _ForwardIterator
888 __uninit_default_n(_ForwardIterator __first, _Size __n)
892 typename iterator_traits<_ForwardIterator>::value_type* __val
896 __first = std::fill_n(__first, __n - 1, *__val);
904 template<
typename _ForwardIterator>
907 __uninitialized_default(_ForwardIterator __first,
908 _ForwardIterator __last)
910#ifdef __cpp_lib_is_constant_evaluated
911 if (std::is_constant_evaluated())
912 return __uninitialized_default_1<false>::
913 __uninit_default(__first, __last);
921 std::__uninitialized_default_1<__is_trivial(_ValueType)
923 __uninit_default(__first, __last);
928 template<
typename _ForwardIterator,
typename _Size>
930 inline _ForwardIterator
931 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
933#ifdef __cpp_lib_is_constant_evaluated
934 if (std::is_constant_evaluated())
935 return __uninitialized_default_n_1<false>::
936 __uninit_default_n(__first, __n);
942 constexpr bool __can_fill
945 return __uninitialized_default_n_1<__is_trivial(_ValueType)
947 __uninit_default_n(__first, __n);
954 template<
typename _ForwardIterator,
typename _Allocator>
956 __uninitialized_default_a(_ForwardIterator __first,
957 _ForwardIterator __last,
960 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__first,
962 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
963 for (; __first != __last; ++__first)
969 template<
typename _ForwardIterator,
typename _Tp>
971 __uninitialized_default_a(_ForwardIterator __first,
972 _ForwardIterator __last,
974 { std::__uninitialized_default(__first, __last); }
980 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
981 _GLIBCXX20_CONSTEXPR _ForwardIterator
982 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
985 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__first,
987 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
988 for (; __n > 0; --__n, (void) ++__first)
997 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
999 inline _ForwardIterator
1000 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
1002 {
return std::__uninitialized_default_n(__first, __n); }
1005 template<
bool _TrivialValueType>
1006 struct __uninitialized_default_novalue_1
1008 template<
typename _ForwardIterator>
1009 _GLIBCXX26_CONSTEXPR
1011 __uninit_default_novalue(_ForwardIterator __first,
1012 _ForwardIterator __last)
1014 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
1015 for (; __first != __last; ++__first)
1022 struct __uninitialized_default_novalue_1<true>
1024 template<
typename _ForwardIterator>
1025 _GLIBCXX26_CONSTEXPR
1027 __uninit_default_novalue(_ForwardIterator, _ForwardIterator)
1032 template<
bool _TrivialValueType>
1033 struct __uninitialized_default_novalue_n_1
1035 template<
typename _ForwardIterator,
typename _Size>
1036 _GLIBCXX26_CONSTEXPR
1037 static _ForwardIterator
1038 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
1040 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
1041 for (; __n > 0; --__n, (void) ++__first)
1049 struct __uninitialized_default_novalue_n_1<true>
1051 template<
typename _ForwardIterator,
typename _Size>
1052 _GLIBCXX26_CONSTEXPR
1053 static _ForwardIterator
1054 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
1055 {
return std::next(__first, __n); }
1060 template<
typename _ForwardIterator>
1061 _GLIBCXX26_CONSTEXPR
1063 __uninitialized_default_novalue(_ForwardIterator __first,
1064 _ForwardIterator __last)
1069 std::__uninitialized_default_novalue_1<
1071 __uninit_default_novalue(__first, __last);
1076 template<
typename _ForwardIterator,
typename _Size>
1077 _GLIBCXX26_CONSTEXPR
1078 inline _ForwardIterator
1079 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
1084 return __uninitialized_default_novalue_n_1<
1086 __uninit_default_novalue_n(__first, __n);
1089 template<
typename _InputIterator,
typename _Size,
1090 typename _ForwardIterator>
1091 _GLIBCXX26_CONSTEXPR
1093 __uninitialized_copy_n(_InputIterator __first, _Size __n,
1096 _UninitDestroyGuard<_ForwardIterator> __guard(__result);
1097 for (; __n > 0; --__n, (void) ++__first, ++__result)
1103 template<
typename _RandomAccessIterator,
typename _Size,
1104 typename _ForwardIterator>
1105 _GLIBCXX26_CONSTEXPR
1106 inline _ForwardIterator
1107 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
1108 _ForwardIterator __result,
1112 template<
typename _InputIterator,
typename _Size,
1113 typename _ForwardIterator>
1114 _GLIBCXX26_CONSTEXPR
1116 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
1119 _UninitDestroyGuard<_ForwardIterator> __guard(__result);
1120 for (; __n > 0; --__n, (void) ++__first, ++__result)
1123 return {__first, __result};
1126 template<
typename _RandomAccessIterator,
typename _Size,
1127 typename _ForwardIterator>
1128 _GLIBCXX26_CONSTEXPR
1130 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
1131 _ForwardIterator __result,
1135 auto __first_res = std::next(__first, __n);
1136 return {__first_res, __second_res};
1151 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
1152 _GLIBCXX26_CONSTEXPR
1153 inline _ForwardIterator
1155 _ForwardIterator __result)
1156 {
return std::__uninitialized_copy_n(__first, __n, __result,
1160 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
1161 _GLIBCXX26_CONSTEXPR
1163 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
1164 _ForwardIterator __result)
1167 std::__uninitialized_copy_n_pair(__first, __n, __result,
1173#ifdef __glibcxx_raw_memory_algorithms
1180 template <
typename _ForwardIterator>
1181 _GLIBCXX26_CONSTEXPR
1184 _ForwardIterator __last)
1186 std::__uninitialized_default_novalue(__first, __last);
1196 template <
typename _ForwardIterator,
typename _Size>
1197 _GLIBCXX26_CONSTEXPR
1198 inline _ForwardIterator
1201 return std::__uninitialized_default_novalue_n(__first, __count);
1210 template <
typename _ForwardIterator>
1211 _GLIBCXX26_CONSTEXPR
1214 _ForwardIterator __last)
1216 return std::__uninitialized_default(__first, __last);
1226 template <
typename _ForwardIterator,
typename _Size>
1227 _GLIBCXX26_CONSTEXPR
1228 inline _ForwardIterator
1231 return std::__uninitialized_default_n(__first, __count);
1242 template <
typename _InputIterator,
typename _ForwardIterator>
1243 _GLIBCXX26_CONSTEXPR
1244 inline _ForwardIterator
1246 _ForwardIterator __result)
1249 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1250 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
1261 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
1262 _GLIBCXX26_CONSTEXPR
1265 _ForwardIterator __result)
1267 auto __res = std::__uninitialized_copy_n_pair
1268 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1270 return {__res.first.base(), __res.second};
1274#if __cplusplus >= 201103L
1277 template<
typename _Tp,
typename _Up,
typename _Allocator>
1278 _GLIBCXX20_CONSTEXPR
1280 __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig,
1281 _Allocator& __alloc)
1288 __traits::construct(__alloc, __dest,
std::move(*__orig));
1294 template<
typename _Tp,
typename =
void>
1295 struct __is_bitwise_relocatable
1296 : __bool_constant<__is_trivial(_Tp)>
1299 template <
typename _InputIterator,
typename _ForwardIterator,
1300 typename _Allocator>
1301 _GLIBCXX20_CONSTEXPR
1302 inline _ForwardIterator
1303 __relocate_a_1(_InputIterator __first, _InputIterator __last,
1304 _ForwardIterator __result, _Allocator& __alloc)
1305 noexcept(
noexcept(std::__relocate_object_a(
std::addressof(*__result),
1313 static_assert(std::is_same<_ValueType, _ValueType2>::value,
1314 "relocation is only possible for values of the same type");
1315 _ForwardIterator __cur = __result;
1316 for (; __first != __last; ++__first, (void)++__cur)
1323 template <
typename _Tp,
typename _Up>
1324 _GLIBCXX20_CONSTEXPR
1325 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
1326 __relocate_a_1(_Tp* __first, _Tp* __last,
1330 ptrdiff_t __count = __last - __first;
1333#ifdef __cpp_lib_is_constant_evaluated
1334 if (std::is_constant_evaluated())
1338 __gnu_cxx::__normal_iterator<_Tp*, void> __out(__result);
1339 __out = std::__relocate_a_1(__first, __last, __out, __alloc);
1340 return __out.base();
1343 __builtin_memcpy(__result, __first, __count *
sizeof(_Tp));
1345 return __result + __count;
1349 template <
typename _InputIterator,
typename _ForwardIterator,
1350 typename _Allocator>
1351 _GLIBCXX20_CONSTEXPR
1352 inline _ForwardIterator
1353 __relocate_a(_InputIterator __first, _InputIterator __last,
1354 _ForwardIterator __result, _Allocator& __alloc)
1355 noexcept(
noexcept(__relocate_a_1(std::__niter_base(__first),
1356 std::__niter_base(__last),
1357 std::__niter_base(__result), __alloc)))
1359 return std::__relocate_a_1(std::__niter_base(__first),
1360 std::__niter_base(__last),
1361 std::__niter_base(__result), __alloc);
1369_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.