56#ifndef _STL_UNINITIALIZED_H
57#define _STL_UNINITIALIZED_H 1
59#if __cplusplus >= 201103L
66#if __cplusplus >= 201703L
70namespace std _GLIBCXX_VISIBILITY(default)
72_GLIBCXX_BEGIN_NAMESPACE_VERSION
80#if __cplusplus >= 201103L
81 template<
typename _ValueType,
typename _Tp>
83 __check_constructible()
90 static_assert(is_constructible<_ValueType, _Tp>::value,
91 "result type must be constructible from input type");
99# define _GLIBCXX_USE_ASSIGN_FOR_INIT(T, U) \
100 __is_trivial(T) && __is_assignable(T&, U) \
101 && std::__check_constructible<T, U>()
106# define _GLIBCXX_USE_ASSIGN_FOR_INIT(T, U) \
107 __is_trivial(T) && __is_assignable(T&, U)
110 template<
typename _InputIterator,
typename _ForwardIterator>
113 __do_uninit_copy(_InputIterator __first, _InputIterator __last,
114 _ForwardIterator __result)
116 _ForwardIterator __cur = __result;
119 for (; __first != __last; ++__first, (void)++__cur)
126 __throw_exception_again;
130 template<
bool _TrivialValueTypes>
131 struct __uninitialized_copy
133 template<
typename _InputIterator,
typename _ForwardIterator>
134 static _ForwardIterator
135 __uninit_copy(_InputIterator __first, _InputIterator __last,
136 _ForwardIterator __result)
137 {
return std::__do_uninit_copy(__first, __last, __result); }
141 struct __uninitialized_copy<true>
143 template<
typename _InputIterator,
typename _ForwardIterator>
144 static _ForwardIterator
145 __uninit_copy(_InputIterator __first, _InputIterator __last,
146 _ForwardIterator __result)
147 {
return std::copy(__first, __last, __result); }
161 template<
typename _InputIterator,
typename _ForwardIterator>
162 inline _ForwardIterator
164 _ForwardIterator __result)
174 const bool __can_memmove = __is_trivial(_ValueType1);
176#if __cplusplus < 201103L
179 using _From =
decltype(*__first);
181 const bool __assignable
182 = _GLIBCXX_USE_ASSIGN_FOR_INIT(_ValueType2, _From);
184 return std::__uninitialized_copy<__can_memmove && __assignable>::
185 __uninit_copy(__first, __last, __result);
190 template<
typename _ForwardIterator,
typename _Tp>
191 _GLIBCXX20_CONSTEXPR
void
192 __do_uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
195 _ForwardIterator __cur = __first;
198 for (; __cur != __last; ++__cur)
204 __throw_exception_again;
208 template<
bool _TrivialValueType>
209 struct __uninitialized_fill
211 template<
typename _ForwardIterator,
typename _Tp>
213 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
215 { std::__do_uninit_fill(__first, __last, __x); }
219 struct __uninitialized_fill<true>
221 template<
typename _ForwardIterator,
typename _Tp>
223 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
225 { std::fill(__first, __last, __x); }
239 template<
typename _ForwardIterator,
typename _Tp>
249 const bool __can_fill
250 = _GLIBCXX_USE_ASSIGN_FOR_INIT(_ValueType,
const _Tp&);
252 std::__uninitialized_fill<__can_fill>::
253 __uninit_fill(__first, __last, __x);
258 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
261 __do_uninit_fill_n(_ForwardIterator __first, _Size __n,
const _Tp& __x)
263 _ForwardIterator __cur = __first;
266 for (; __n > 0; --__n, (void) ++__cur)
273 __throw_exception_again;
277 template<
bool _TrivialValueType>
278 struct __uninitialized_fill_n
280 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
281 static _ForwardIterator
282 __uninit_fill_n(_ForwardIterator __first, _Size __n,
284 {
return std::__do_uninit_fill_n(__first, __n, __x); }
288 struct __uninitialized_fill_n<true>
290 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
291 static _ForwardIterator
292 __uninit_fill_n(_ForwardIterator __first, _Size __n,
294 {
return std::fill_n(__first, __n, __x); }
310 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
311 inline _ForwardIterator
319 const bool __can_fill
320 = _GLIBCXX_USE_ASSIGN_FOR_INIT(_ValueType,
const _Tp&)
324 && __is_integer<_Size>::__value;
326 return __uninitialized_fill_n<__can_fill>::
327 __uninit_fill_n(__first, __n, __x);
330#undef _GLIBCXX_USE_ASSIGN_FOR_INIT
340 template<
typename _InputIterator,
typename _ForwardIterator,
344 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
345 _ForwardIterator __result, _Allocator& __alloc)
347 _ForwardIterator __cur = __result;
351 for (; __first != __last; ++__first, (void)++__cur)
358 __throw_exception_again;
362 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp>
364 inline _ForwardIterator
365 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
366 _ForwardIterator __result, allocator<_Tp>&)
368#ifdef __cpp_lib_is_constant_evaluated
370 return std::__do_uninit_copy(__first, __last, __result);
375 template<
typename _InputIterator,
typename _ForwardIterator,
378 inline _ForwardIterator
379 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
380 _ForwardIterator __result, _Allocator& __alloc)
382 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
383 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
387 template<
typename _InputIterator,
typename _ForwardIterator,
390 inline _ForwardIterator
391 __uninitialized_move_if_noexcept_a(_InputIterator __first,
392 _InputIterator __last,
393 _ForwardIterator __result,
396 return std::__uninitialized_copy_a
397 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
398 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
401 template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
404 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
405 const _Tp& __x, _Allocator& __alloc)
407 _ForwardIterator __cur = __first;
411 for (; __cur != __last; ++__cur)
417 __throw_exception_again;
421 template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
424 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
425 const _Tp& __x, allocator<_Tp2>&)
427#ifdef __cpp_lib_is_constant_evaluated
429 return std::__do_uninit_fill(__first, __last, __x);
434 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
438 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
439 const _Tp& __x, _Allocator& __alloc)
441 _ForwardIterator __cur = __first;
445 for (; __n > 0; --__n, (void) ++__cur)
452 __throw_exception_again;
456 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
459 inline _ForwardIterator
460 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
461 const _Tp& __x, allocator<_Tp2>&)
463#ifdef __cpp_lib_is_constant_evaluated
465 return std::__do_uninit_fill_n(__first, __n, __x);
480 template<
typename _InputIterator1,
typename _InputIterator2,
481 typename _ForwardIterator,
typename _Allocator>
482 inline _ForwardIterator
483 __uninitialized_copy_move(_InputIterator1 __first1,
484 _InputIterator1 __last1,
485 _InputIterator2 __first2,
486 _InputIterator2 __last2,
487 _ForwardIterator __result,
490 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
495 return std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
500 __throw_exception_again;
508 template<
typename _InputIterator1,
typename _InputIterator2,
509 typename _ForwardIterator,
typename _Allocator>
510 inline _ForwardIterator
511 __uninitialized_move_copy(_InputIterator1 __first1,
512 _InputIterator1 __last1,
513 _InputIterator2 __first2,
514 _InputIterator2 __last2,
515 _ForwardIterator __result,
518 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
523 return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
528 __throw_exception_again;
535 template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
537 inline _ForwardIterator
538 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
539 const _Tp& __x, _InputIterator __first,
540 _InputIterator __last, _Allocator& __alloc)
542 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
545 return std::__uninitialized_move_a(__first, __last, __mid, __alloc);
550 __throw_exception_again;
557 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
560 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
561 _ForwardIterator __first2,
562 _ForwardIterator __last2,
const _Tp& __x,
565 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
570 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
575 __throw_exception_again;
581#if __cplusplus >= 201103L
587 template<
bool _TrivialValueType>
588 struct __uninitialized_default_1
590 template<
typename _ForwardIterator>
592 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
594 _ForwardIterator __cur = __first;
597 for (; __cur != __last; ++__cur)
603 __throw_exception_again;
609 struct __uninitialized_default_1<true>
611 template<
typename _ForwardIterator>
613 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
615 if (__first == __last)
618 typename iterator_traits<_ForwardIterator>::value_type* __val
621 if (++__first != __last)
622 std::fill(__first, __last, *__val);
626 template<
bool _TrivialValueType>
627 struct __uninitialized_default_n_1
629 template<
typename _ForwardIterator,
typename _Size>
631 static _ForwardIterator
632 __uninit_default_n(_ForwardIterator __first, _Size __n)
634 _ForwardIterator __cur = __first;
637 for (; __n > 0; --__n, (void) ++__cur)
644 __throw_exception_again;
650 struct __uninitialized_default_n_1<true>
652 template<
typename _ForwardIterator,
typename _Size>
654 static _ForwardIterator
655 __uninit_default_n(_ForwardIterator __first, _Size __n)
659 typename iterator_traits<_ForwardIterator>::value_type* __val
663 __first = std::fill_n(__first, __n - 1, *__val);
671 template<
typename _ForwardIterator>
673 __uninitialized_default(_ForwardIterator __first,
674 _ForwardIterator __last)
676 typedef typename iterator_traits<_ForwardIterator>::value_type
679 const bool __assignable = is_copy_assignable<_ValueType>::value;
681 std::__uninitialized_default_1<__is_trivial(_ValueType)
683 __uninit_default(__first, __last);
688 template<
typename _ForwardIterator,
typename _Size>
690 inline _ForwardIterator
691 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
693 typedef typename iterator_traits<_ForwardIterator>::value_type
696 constexpr bool __can_fill
697 = __and_<is_integral<_Size>, is_copy_assignable<_ValueType>>::value;
699 return __uninitialized_default_n_1<__is_trivial(_ValueType)
701 __uninit_default_n(__first, __n);
708 template<
typename _ForwardIterator,
typename _Allocator>
710 __uninitialized_default_a(_ForwardIterator __first,
711 _ForwardIterator __last,
714 _ForwardIterator __cur = __first;
718 for (; __cur != __last; ++__cur)
724 __throw_exception_again;
728 template<
typename _ForwardIterator,
typename _Tp>
730 __uninitialized_default_a(_ForwardIterator __first,
731 _ForwardIterator __last,
733 { std::__uninitialized_default(__first, __last); }
739 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
740 _GLIBCXX20_CONSTEXPR _ForwardIterator
741 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
744 _ForwardIterator __cur = __first;
748 for (; __n > 0; --__n, (void) ++__cur)
755 __throw_exception_again;
761 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
763 inline _ForwardIterator
764 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
766 {
return std::__uninitialized_default_n(__first, __n); }
768 template<
bool _TrivialValueType>
769 struct __uninitialized_default_novalue_1
771 template<
typename _ForwardIterator>
773 __uninit_default_novalue(_ForwardIterator __first,
774 _ForwardIterator __last)
776 _ForwardIterator __cur = __first;
779 for (; __cur != __last; ++__cur)
785 __throw_exception_again;
791 struct __uninitialized_default_novalue_1<true>
793 template<
typename _ForwardIterator>
795 __uninit_default_novalue(_ForwardIterator __first,
796 _ForwardIterator __last)
801 template<
bool _TrivialValueType>
802 struct __uninitialized_default_novalue_n_1
804 template<
typename _ForwardIterator,
typename _Size>
805 static _ForwardIterator
806 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
808 _ForwardIterator __cur = __first;
811 for (; __n > 0; --__n, (void) ++__cur)
818 __throw_exception_again;
824 struct __uninitialized_default_novalue_n_1<true>
826 template<
typename _ForwardIterator,
typename _Size>
827 static _ForwardIterator
828 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
829 {
return std::next(__first, __n); }
834 template<
typename _ForwardIterator>
836 __uninitialized_default_novalue(_ForwardIterator __first,
837 _ForwardIterator __last)
839 typedef typename iterator_traits<_ForwardIterator>::value_type
842 std::__uninitialized_default_novalue_1<
843 is_trivially_default_constructible<_ValueType>::value>::
844 __uninit_default_novalue(__first, __last);
849 template<
typename _ForwardIterator,
typename _Size>
850 inline _ForwardIterator
851 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
853 typedef typename iterator_traits<_ForwardIterator>::value_type
856 return __uninitialized_default_novalue_n_1<
857 is_trivially_default_constructible<_ValueType>::value>::
858 __uninit_default_novalue_n(__first, __n);
861 template<
typename _InputIterator,
typename _Size,
862 typename _ForwardIterator>
864 __uninitialized_copy_n(_InputIterator __first, _Size __n,
865 _ForwardIterator __result, input_iterator_tag)
867 _ForwardIterator __cur = __result;
870 for (; __n > 0; --__n, (void) ++__first, ++__cur)
877 __throw_exception_again;
881 template<
typename _RandomAccessIterator,
typename _Size,
882 typename _ForwardIterator>
883 inline _ForwardIterator
884 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
885 _ForwardIterator __result,
886 random_access_iterator_tag)
889 template<
typename _InputIterator,
typename _Size,
890 typename _ForwardIterator>
891 pair<_InputIterator, _ForwardIterator>
892 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
893 _ForwardIterator __result, input_iterator_tag)
895 _ForwardIterator __cur = __result;
898 for (; __n > 0; --__n, (void) ++__first, ++__cur)
900 return {__first, __cur};
905 __throw_exception_again;
909 template<
typename _RandomAccessIterator,
typename _Size,
910 typename _ForwardIterator>
911 inline pair<_RandomAccessIterator, _ForwardIterator>
912 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
913 _ForwardIterator __result,
914 random_access_iterator_tag)
917 auto __first_res = std::next(__first, __n);
918 return {__first_res, __second_res};
933 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
934 inline _ForwardIterator
936 _ForwardIterator __result)
937 {
return std::__uninitialized_copy_n(__first, __n, __result,
941 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
942 inline pair<_InputIterator, _ForwardIterator>
943 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
944 _ForwardIterator __result)
947 std::__uninitialized_copy_n_pair(__first, __n, __result,
953#if __cplusplus >= 201703L
954# define __cpp_lib_raw_memory_algorithms 201606L
962 template <
typename _ForwardIterator>
965 _ForwardIterator __last)
967 __uninitialized_default_novalue(__first, __last);
977 template <
typename _ForwardIterator,
typename _Size>
978 inline _ForwardIterator
981 return __uninitialized_default_novalue_n(__first, __count);
990 template <
typename _ForwardIterator>
993 _ForwardIterator __last)
995 return __uninitialized_default(__first, __last);
1005 template <
typename _ForwardIterator,
typename _Size>
1006 inline _ForwardIterator
1009 return __uninitialized_default_n(__first, __count);
1020 template <
typename _InputIterator,
typename _ForwardIterator>
1021 inline _ForwardIterator
1023 _ForwardIterator __result)
1026 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1027 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
1038 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
1039 inline pair<_InputIterator, _ForwardIterator>
1041 _ForwardIterator __result)
1043 auto __res = std::__uninitialized_copy_n_pair
1044 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1046 return {__res.first.base(), __res.second};
1050#if __cplusplus >= 201103L
1053 template<
typename _Tp,
typename _Up,
typename _Allocator>
1054 _GLIBCXX20_CONSTEXPR
1056 __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig,
1057 _Allocator& __alloc)
1064 __traits::construct(__alloc, __dest,
std::move(*__orig));
1070 template<
typename _Tp,
typename =
void>
1071 struct __is_bitwise_relocatable
1072 : is_trivial<_Tp> { };
1074 template <
typename _InputIterator,
typename _ForwardIterator,
1075 typename _Allocator>
1076 _GLIBCXX20_CONSTEXPR
1077 inline _ForwardIterator
1078 __relocate_a_1(_InputIterator __first, _InputIterator __last,
1079 _ForwardIterator __result, _Allocator& __alloc)
1080 noexcept(
noexcept(std::__relocate_object_a(
std::addressof(*__result),
1084 typedef typename iterator_traits<_InputIterator>::value_type
1086 typedef typename iterator_traits<_ForwardIterator>::value_type
1089 "relocation is only possible for values of the same type");
1090 _ForwardIterator __cur = __result;
1091 for (; __first != __last; ++__first, (void)++__cur)
1097 template <
typename _Tp,
typename _Up>
1098 _GLIBCXX20_CONSTEXPR
1099 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
1100 __relocate_a_1(_Tp* __first, _Tp* __last,
1102 [[__maybe_unused__]] allocator<_Up>& __alloc)
noexcept
1104 ptrdiff_t __count = __last - __first;
1107#ifdef __cpp_lib_is_constant_evaluated
1112 __gnu_cxx::__normal_iterator<_Tp*, void> __out(__result);
1113 __out = std::__relocate_a_1(__first, __last, __out, __alloc);
1114 return __out.base();
1117 __builtin_memmove(__result, __first, __count *
sizeof(_Tp));
1119 return __result + __count;
1123 template <
typename _InputIterator,
typename _ForwardIterator,
1124 typename _Allocator>
1125 _GLIBCXX20_CONSTEXPR
1126 inline _ForwardIterator
1127 __relocate_a(_InputIterator __first, _InputIterator __last,
1128 _ForwardIterator __result, _Allocator& __alloc)
1129 noexcept(
noexcept(__relocate_a_1(std::__niter_base(__first),
1130 std::__niter_base(__last),
1131 std::__niter_base(__result), __alloc)))
1133 return std::__relocate_a_1(std::__niter_base(__first),
1134 std::__niter_base(__last),
1135 std::__niter_base(__result), __alloc);
1143_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 bool is_constant_evaluated() noexcept
Returns true only when called during constant evaluation.
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 void _Construct(_Tp *__p, _Args &&... __args)
constexpr void _Destroy(_ForwardIterator __first, _ForwardIterator __last, _Allocator &__alloc)
Uniform interface to all allocator types.
static constexpr auto construct(_Alloc &__a, _Tp *__p, _Args &&... __args) noexcept(noexcept(_S_construct(__a, __p, std::forward< _Args >(__args)...))) -> decltype(_S_construct(__a, __p, std::forward< _Args >(__args)...))
Construct an object of type _Tp
Traits class for iterators.
Uniform interface to C++98 and C++11 allocators.