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)
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
176#if __cplusplus < 201103L
179 using _From =
decltype(*__first);
181 const bool __assignable
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,
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>
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,
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
324 && __is_integer<_Size>::__value;
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
375 template<
typename _InputIterator,
typename _ForwardIterator,
378 inline _ForwardIterator
379 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
380 _ForwardIterator __result, _Allocator& __alloc)
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,
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
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
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,
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,
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)
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,
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;
683 __uninit_default(__first, __last);
688 template<
typename _ForwardIterator,
typename _Size>
690 inline _ForwardIterator
691 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
693#ifdef __cpp_lib_is_constant_evaluated
695 return __uninitialized_default_n_1<false>::
696 __uninit_default_n(__first, __n);
699 typedef typename iterator_traits<_ForwardIterator>::value_type
702 constexpr bool __can_fill
703 = __and_<is_integral<_Size>, is_copy_assignable<_ValueType>>::value;
705 return __uninitialized_default_n_1<__is_trivial(_ValueType)
707 __uninit_default_n(__first, __n);
714 template<
typename _ForwardIterator,
typename _Allocator>
716 __uninitialized_default_a(_ForwardIterator __first,
717 _ForwardIterator __last,
720 _ForwardIterator __cur = __first;
724 for (; __cur != __last; ++__cur)
730 __throw_exception_again;
734 template<
typename _ForwardIterator,
typename _Tp>
736 __uninitialized_default_a(_ForwardIterator __first,
737 _ForwardIterator __last,
745 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
746 _GLIBCXX20_CONSTEXPR _ForwardIterator
747 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
750 _ForwardIterator __cur = __first;
754 for (; __n > 0; --__n, (void) ++__cur)
761 __throw_exception_again;
767 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
769 inline _ForwardIterator
770 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
774 template<
bool _TrivialValueType>
775 struct __uninitialized_default_novalue_1
777 template<
typename _ForwardIterator>
779 __uninit_default_novalue(_ForwardIterator __first,
780 _ForwardIterator __last)
782 _ForwardIterator __cur = __first;
785 for (; __cur != __last; ++__cur)
791 __throw_exception_again;
797 struct __uninitialized_default_novalue_1<true>
799 template<
typename _ForwardIterator>
801 __uninit_default_novalue(_ForwardIterator __first,
802 _ForwardIterator __last)
807 template<
bool _TrivialValueType>
808 struct __uninitialized_default_novalue_n_1
810 template<
typename _ForwardIterator,
typename _Size>
811 static _ForwardIterator
812 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
814 _ForwardIterator __cur = __first;
817 for (; __n > 0; --__n, (void) ++__cur)
824 __throw_exception_again;
830 struct __uninitialized_default_novalue_n_1<true>
832 template<
typename _ForwardIterator,
typename _Size>
833 static _ForwardIterator
834 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
835 {
return std::next(__first, __n); }
840 template<
typename _ForwardIterator>
842 __uninitialized_default_novalue(_ForwardIterator __first,
843 _ForwardIterator __last)
845 typedef typename iterator_traits<_ForwardIterator>::value_type
849 is_trivially_default_constructible<_ValueType>::value>::
850 __uninit_default_novalue(__first, __last);
855 template<
typename _ForwardIterator,
typename _Size>
856 inline _ForwardIterator
857 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
859 typedef typename iterator_traits<_ForwardIterator>::value_type
862 return __uninitialized_default_novalue_n_1<
863 is_trivially_default_constructible<_ValueType>::value>::
864 __uninit_default_novalue_n(__first, __n);
867 template<
typename _InputIterator,
typename _Size,
868 typename _ForwardIterator>
870 __uninitialized_copy_n(_InputIterator __first, _Size __n,
871 _ForwardIterator __result, input_iterator_tag)
873 _ForwardIterator __cur = __result;
876 for (; __n > 0; --__n, (void) ++__first, ++__cur)
883 __throw_exception_again;
887 template<
typename _RandomAccessIterator,
typename _Size,
888 typename _ForwardIterator>
889 inline _ForwardIterator
890 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
891 _ForwardIterator __result,
892 random_access_iterator_tag)
895 template<
typename _InputIterator,
typename _Size,
896 typename _ForwardIterator>
897 pair<_InputIterator, _ForwardIterator>
898 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
899 _ForwardIterator __result, input_iterator_tag)
901 _ForwardIterator __cur = __result;
904 for (; __n > 0; --__n, (void) ++__first, ++__cur)
906 return {__first, __cur};
911 __throw_exception_again;
915 template<
typename _RandomAccessIterator,
typename _Size,
916 typename _ForwardIterator>
917 inline pair<_RandomAccessIterator, _ForwardIterator>
918 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
919 _ForwardIterator __result,
920 random_access_iterator_tag)
923 auto __first_res = std::next(__first, __n);
924 return {__first_res, __second_res};
939 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
940 inline _ForwardIterator
943 {
return std::__uninitialized_copy_n(__first, __n, __result,
947 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
948 inline pair<_InputIterator, _ForwardIterator>
949 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
950 _ForwardIterator __result)
959#if __cplusplus >= 201703L
960# define __cpp_lib_raw_memory_algorithms 201606L
968 template <
typename _ForwardIterator>
983 template <
typename _ForwardIterator,
typename _Size>
984 inline _ForwardIterator
996 template <
typename _ForwardIterator>
1011 template <
typename _ForwardIterator,
typename _Size>
1012 inline _ForwardIterator
1026 template <
typename _InputIterator,
typename _ForwardIterator>
1027 inline _ForwardIterator
1032 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1033 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
1044 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
1045 inline pair<_InputIterator, _ForwardIterator>
1050 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1056#if __cplusplus >= 201103L
1059 template<
typename _Tp,
typename _Up,
typename _Allocator>
1060 _GLIBCXX20_CONSTEXPR
1062 __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig,
1063 _Allocator& __alloc)
1070 __traits::construct(__alloc, __dest,
std::move(*__orig));
1076 template<
typename _Tp,
typename =
void>
1077 struct __is_bitwise_relocatable
1078 : is_trivial<_Tp> { };
1080 template <
typename _InputIterator,
typename _ForwardIterator,
1081 typename _Allocator>
1082 _GLIBCXX20_CONSTEXPR
1083 inline _ForwardIterator
1084 __relocate_a_1(_InputIterator __first, _InputIterator __last,
1085 _ForwardIterator __result, _Allocator& __alloc)
1090 typedef typename iterator_traits<_InputIterator>::value_type
1092 typedef typename iterator_traits<_ForwardIterator>::value_type
1095 "relocation is only possible for values of the same type");
1096 _ForwardIterator __cur = __result;
1097 for (; __first != __last; ++__first, (void)++__cur)
1103 template <
typename _Tp,
typename _Up>
1104 _GLIBCXX20_CONSTEXPR
1105 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
1106 __relocate_a_1(_Tp* __first, _Tp* __last,
1108 [[__maybe_unused__]] allocator<_Up>& __alloc)
noexcept
1110 ptrdiff_t __count = __last - __first;
1113#ifdef __cpp_lib_is_constant_evaluated
1118 __gnu_cxx::__normal_iterator<_Tp*, void> __out(__result);
1120 return __out.base();
1123 __builtin_memmove(__result, __first, __count *
sizeof(_Tp));
1125 return __result + __count;
1129 template <
typename _InputIterator,
typename _ForwardIterator,
1130 typename _Allocator>
1131 _GLIBCXX20_CONSTEXPR
1132 inline _ForwardIterator
1133 __relocate_a(_InputIterator __first, _InputIterator __last,
1134 _ForwardIterator __result, _Allocator& __alloc)
1135 noexcept(
noexcept(__relocate_a_1(std::__niter_base(__first),
1136 std::__niter_base(__last),
1137 std::__niter_base(__result), __alloc)))
1140 std::__niter_base(__last),
1141 std::__niter_base(__result), __alloc);
1149_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.