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;
363 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp>
365 inline _ForwardIterator
366 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
367 _ForwardIterator __result, allocator<_Tp>&)
369#ifdef __cpp_lib_is_constant_evaluated
371 return std::__do_uninit_copy(__first, __last, __result);
377 template<
typename _InputIterator,
typename _ForwardIterator,
380 inline _ForwardIterator
381 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
382 _ForwardIterator __result, _Allocator& __alloc)
384 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
385 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
389 template<
typename _InputIterator,
typename _ForwardIterator,
392 inline _ForwardIterator
393 __uninitialized_move_if_noexcept_a(_InputIterator __first,
394 _InputIterator __last,
395 _ForwardIterator __result,
398 return std::__uninitialized_copy_a
399 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
400 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
403 template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
406 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
407 const _Tp& __x, _Allocator& __alloc)
409 _ForwardIterator __cur = __first;
413 for (; __cur != __last; ++__cur)
419 __throw_exception_again;
424 template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
427 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
428 const _Tp& __x, allocator<_Tp2>&)
430#ifdef __cpp_lib_is_constant_evaluated
432 return std::__do_uninit_fill(__first, __last, __x);
438 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
442 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
443 const _Tp& __x, _Allocator& __alloc)
445 _ForwardIterator __cur = __first;
449 for (; __n > 0; --__n, (void) ++__cur)
456 __throw_exception_again;
461 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
464 inline _ForwardIterator
465 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
466 const _Tp& __x, allocator<_Tp2>&)
468#ifdef __cpp_lib_is_constant_evaluated
470 return std::__do_uninit_fill_n(__first, __n, __x);
485 template<
typename _InputIterator1,
typename _InputIterator2,
486 typename _ForwardIterator,
typename _Allocator>
487 inline _ForwardIterator
488 __uninitialized_copy_move(_InputIterator1 __first1,
489 _InputIterator1 __last1,
490 _InputIterator2 __first2,
491 _InputIterator2 __last2,
492 _ForwardIterator __result,
495 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
500 return std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
505 __throw_exception_again;
513 template<
typename _InputIterator1,
typename _InputIterator2,
514 typename _ForwardIterator,
typename _Allocator>
515 inline _ForwardIterator
516 __uninitialized_move_copy(_InputIterator1 __first1,
517 _InputIterator1 __last1,
518 _InputIterator2 __first2,
519 _InputIterator2 __last2,
520 _ForwardIterator __result,
523 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
528 return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
533 __throw_exception_again;
540 template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
542 inline _ForwardIterator
543 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
544 const _Tp& __x, _InputIterator __first,
545 _InputIterator __last, _Allocator& __alloc)
547 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
550 return std::__uninitialized_move_a(__first, __last, __mid, __alloc);
555 __throw_exception_again;
562 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
565 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
566 _ForwardIterator __first2,
567 _ForwardIterator __last2,
const _Tp& __x,
570 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
575 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
580 __throw_exception_again;
586#if __cplusplus >= 201103L
592 template<
bool _TrivialValueType>
593 struct __uninitialized_default_1
595 template<
typename _ForwardIterator>
597 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
599 _ForwardIterator __cur = __first;
602 for (; __cur != __last; ++__cur)
608 __throw_exception_again;
614 struct __uninitialized_default_1<true>
616 template<
typename _ForwardIterator>
618 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
620 if (__first == __last)
623 typename iterator_traits<_ForwardIterator>::value_type* __val
626 if (++__first != __last)
627 std::fill(__first, __last, *__val);
631 template<
bool _TrivialValueType>
632 struct __uninitialized_default_n_1
634 template<
typename _ForwardIterator,
typename _Size>
636 static _ForwardIterator
637 __uninit_default_n(_ForwardIterator __first, _Size __n)
639 _ForwardIterator __cur = __first;
642 for (; __n > 0; --__n, (void) ++__cur)
649 __throw_exception_again;
655 struct __uninitialized_default_n_1<true>
657 template<
typename _ForwardIterator,
typename _Size>
659 static _ForwardIterator
660 __uninit_default_n(_ForwardIterator __first, _Size __n)
664 typename iterator_traits<_ForwardIterator>::value_type* __val
668 __first = std::fill_n(__first, __n - 1, *__val);
676 template<
typename _ForwardIterator>
678 __uninitialized_default(_ForwardIterator __first,
679 _ForwardIterator __last)
681 typedef typename iterator_traits<_ForwardIterator>::value_type
684 const bool __assignable = is_copy_assignable<_ValueType>::value;
686 std::__uninitialized_default_1<__is_trivial(_ValueType)
688 __uninit_default(__first, __last);
693 template<
typename _ForwardIterator,
typename _Size>
695 inline _ForwardIterator
696 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
698#ifdef __cpp_lib_is_constant_evaluated
700 return __uninitialized_default_n_1<false>::
701 __uninit_default_n(__first, __n);
704 typedef typename iterator_traits<_ForwardIterator>::value_type
707 constexpr bool __can_fill
708 = __and_<is_integral<_Size>, is_copy_assignable<_ValueType>>::value;
710 return __uninitialized_default_n_1<__is_trivial(_ValueType)
712 __uninit_default_n(__first, __n);
719 template<
typename _ForwardIterator,
typename _Allocator>
721 __uninitialized_default_a(_ForwardIterator __first,
722 _ForwardIterator __last,
725 _ForwardIterator __cur = __first;
729 for (; __cur != __last; ++__cur)
735 __throw_exception_again;
740 template<
typename _ForwardIterator,
typename _Tp>
742 __uninitialized_default_a(_ForwardIterator __first,
743 _ForwardIterator __last,
745 { std::__uninitialized_default(__first, __last); }
751 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
752 _GLIBCXX20_CONSTEXPR _ForwardIterator
753 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
756 _ForwardIterator __cur = __first;
760 for (; __n > 0; --__n, (void) ++__cur)
767 __throw_exception_again;
774 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
776 inline _ForwardIterator
777 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
779 {
return std::__uninitialized_default_n(__first, __n); }
782 template<
bool _TrivialValueType>
783 struct __uninitialized_default_novalue_1
785 template<
typename _ForwardIterator>
787 __uninit_default_novalue(_ForwardIterator __first,
788 _ForwardIterator __last)
790 _ForwardIterator __cur = __first;
793 for (; __cur != __last; ++__cur)
799 __throw_exception_again;
805 struct __uninitialized_default_novalue_1<true>
807 template<
typename _ForwardIterator>
809 __uninit_default_novalue(_ForwardIterator __first,
810 _ForwardIterator __last)
815 template<
bool _TrivialValueType>
816 struct __uninitialized_default_novalue_n_1
818 template<
typename _ForwardIterator,
typename _Size>
819 static _ForwardIterator
820 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
822 _ForwardIterator __cur = __first;
825 for (; __n > 0; --__n, (void) ++__cur)
832 __throw_exception_again;
838 struct __uninitialized_default_novalue_n_1<true>
840 template<
typename _ForwardIterator,
typename _Size>
841 static _ForwardIterator
842 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
843 {
return std::next(__first, __n); }
848 template<
typename _ForwardIterator>
850 __uninitialized_default_novalue(_ForwardIterator __first,
851 _ForwardIterator __last)
853 typedef typename iterator_traits<_ForwardIterator>::value_type
856 std::__uninitialized_default_novalue_1<
857 is_trivially_default_constructible<_ValueType>::value>::
858 __uninit_default_novalue(__first, __last);
863 template<
typename _ForwardIterator,
typename _Size>
864 inline _ForwardIterator
865 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
867 typedef typename iterator_traits<_ForwardIterator>::value_type
870 return __uninitialized_default_novalue_n_1<
871 is_trivially_default_constructible<_ValueType>::value>::
872 __uninit_default_novalue_n(__first, __n);
875 template<
typename _InputIterator,
typename _Size,
876 typename _ForwardIterator>
878 __uninitialized_copy_n(_InputIterator __first, _Size __n,
879 _ForwardIterator __result, input_iterator_tag)
881 _ForwardIterator __cur = __result;
884 for (; __n > 0; --__n, (void) ++__first, ++__cur)
891 __throw_exception_again;
895 template<
typename _RandomAccessIterator,
typename _Size,
896 typename _ForwardIterator>
897 inline _ForwardIterator
898 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
899 _ForwardIterator __result,
900 random_access_iterator_tag)
903 template<
typename _InputIterator,
typename _Size,
904 typename _ForwardIterator>
905 pair<_InputIterator, _ForwardIterator>
906 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
907 _ForwardIterator __result, input_iterator_tag)
909 _ForwardIterator __cur = __result;
912 for (; __n > 0; --__n, (void) ++__first, ++__cur)
914 return {__first, __cur};
919 __throw_exception_again;
923 template<
typename _RandomAccessIterator,
typename _Size,
924 typename _ForwardIterator>
925 inline pair<_RandomAccessIterator, _ForwardIterator>
926 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
927 _ForwardIterator __result,
928 random_access_iterator_tag)
931 auto __first_res = std::next(__first, __n);
932 return {__first_res, __second_res};
947 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
948 inline _ForwardIterator
950 _ForwardIterator __result)
951 {
return std::__uninitialized_copy_n(__first, __n, __result,
955 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
956 inline pair<_InputIterator, _ForwardIterator>
957 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
958 _ForwardIterator __result)
961 std::__uninitialized_copy_n_pair(__first, __n, __result,
967#if __cplusplus >= 201703L
968# define __cpp_lib_raw_memory_algorithms 201606L
976 template <
typename _ForwardIterator>
979 _ForwardIterator __last)
981 __uninitialized_default_novalue(__first, __last);
991 template <
typename _ForwardIterator,
typename _Size>
992 inline _ForwardIterator
995 return __uninitialized_default_novalue_n(__first, __count);
1004 template <
typename _ForwardIterator>
1007 _ForwardIterator __last)
1009 return __uninitialized_default(__first, __last);
1019 template <
typename _ForwardIterator,
typename _Size>
1020 inline _ForwardIterator
1023 return __uninitialized_default_n(__first, __count);
1034 template <
typename _InputIterator,
typename _ForwardIterator>
1035 inline _ForwardIterator
1037 _ForwardIterator __result)
1040 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1041 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
1052 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
1053 inline pair<_InputIterator, _ForwardIterator>
1055 _ForwardIterator __result)
1057 auto __res = std::__uninitialized_copy_n_pair
1058 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1060 return {__res.first.base(), __res.second};
1064#if __cplusplus >= 201103L
1067 template<
typename _Tp,
typename _Up,
typename _Allocator>
1068 _GLIBCXX20_CONSTEXPR
1070 __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig,
1071 _Allocator& __alloc)
1078 __traits::construct(__alloc, __dest,
std::move(*__orig));
1084 template<
typename _Tp,
typename =
void>
1085 struct __is_bitwise_relocatable
1086 : is_trivial<_Tp> { };
1088 template <
typename _InputIterator,
typename _ForwardIterator,
1089 typename _Allocator>
1090 _GLIBCXX20_CONSTEXPR
1091 inline _ForwardIterator
1092 __relocate_a_1(_InputIterator __first, _InputIterator __last,
1093 _ForwardIterator __result, _Allocator& __alloc)
1094 noexcept(
noexcept(std::__relocate_object_a(
std::addressof(*__result),
1098 typedef typename iterator_traits<_InputIterator>::value_type
1100 typedef typename iterator_traits<_ForwardIterator>::value_type
1103 "relocation is only possible for values of the same type");
1104 _ForwardIterator __cur = __result;
1105 for (; __first != __last; ++__first, (void)++__cur)
1112 template <
typename _Tp,
typename _Up>
1113 _GLIBCXX20_CONSTEXPR
1114 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
1115 __relocate_a_1(_Tp* __first, _Tp* __last,
1117 [[__maybe_unused__]] allocator<_Up>& __alloc)
noexcept
1119 ptrdiff_t __count = __last - __first;
1122#ifdef __cpp_lib_is_constant_evaluated
1127 __gnu_cxx::__normal_iterator<_Tp*, void> __out(__result);
1128 __out = std::__relocate_a_1(__first, __last, __out, __alloc);
1129 return __out.base();
1132 __builtin_memmove(__result, __first, __count *
sizeof(_Tp));
1134 return __result + __count;
1138 template <
typename _InputIterator,
typename _ForwardIterator,
1139 typename _Allocator>
1140 _GLIBCXX20_CONSTEXPR
1141 inline _ForwardIterator
1142 __relocate_a(_InputIterator __first, _InputIterator __last,
1143 _ForwardIterator __result, _Allocator& __alloc)
1144 noexcept(
noexcept(__relocate_a_1(std::__niter_base(__first),
1145 std::__niter_base(__last),
1146 std::__niter_base(__result), __alloc)))
1148 return std::__relocate_a_1(std::__niter_base(__first),
1149 std::__niter_base(__last),
1150 std::__niter_base(__result), __alloc);
1158_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)
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.