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 template<
bool _TrivialValueTypes>
81 struct __uninitialized_copy
83 template<
typename _InputIterator,
typename _ForwardIterator>
84 static _ForwardIterator
85 __uninit_copy(_InputIterator __first, _InputIterator __last,
86 _ForwardIterator __result)
88 _ForwardIterator __cur = __result;
91 for (; __first != __last; ++__first, (void)++__cur)
98 __throw_exception_again;
104 struct __uninitialized_copy<true>
106 template<
typename _InputIterator,
typename _ForwardIterator>
107 static _ForwardIterator
108 __uninit_copy(_InputIterator __first, _InputIterator __last,
109 _ForwardIterator __result)
110 {
return std::copy(__first, __last, __result); }
124 template<
typename _InputIterator,
typename _ForwardIterator>
125 inline _ForwardIterator
127 _ForwardIterator __result)
133#if __cplusplus < 201103L
134 const bool __assignable =
true;
139 "result type must be constructible from value type of input range");
148 return std::__uninitialized_copy<__is_trivial(_ValueType1)
149 && __is_trivial(_ValueType2)
151 __uninit_copy(__first, __last, __result);
156 template<
bool _TrivialValueType>
157 struct __uninitialized_fill
159 template<
typename _ForwardIterator,
typename _Tp>
161 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
164 _ForwardIterator __cur = __first;
167 for (; __cur != __last; ++__cur)
173 __throw_exception_again;
179 struct __uninitialized_fill<true>
181 template<
typename _ForwardIterator,
typename _Tp>
183 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
185 { std::fill(__first, __last, __x); }
199 template<
typename _ForwardIterator,
typename _Tp>
206#if __cplusplus < 201103L
207 const bool __assignable =
true;
212 "result type must be constructible from input type");
219 std::__uninitialized_fill<__is_trivial(_ValueType) && __assignable>::
220 __uninit_fill(__first, __last, __x);
225 template<
bool _TrivialValueType>
226 struct __uninitialized_fill_n
228 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
229 static _ForwardIterator
230 __uninit_fill_n(_ForwardIterator __first, _Size __n,
233 _ForwardIterator __cur = __first;
236 for (; __n > 0; --__n, (void) ++__cur)
243 __throw_exception_again;
249 struct __uninitialized_fill_n<true>
251 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
252 static _ForwardIterator
253 __uninit_fill_n(_ForwardIterator __first, _Size __n,
255 {
return std::fill_n(__first, __n, __x); }
271 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
272 inline _ForwardIterator
283#if __cplusplus < 201103L
284 const bool __can_fill = __is_integer<_Size>::__value;
289 "result type must be constructible from input type");
293 constexpr bool __can_fill
296 return __uninitialized_fill_n<__is_trivial(_ValueType) && __can_fill>::
297 __uninit_fill_n(__first, __n, __x);
308 template<
typename _InputIterator,
typename _ForwardIterator,
311 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
312 _ForwardIterator __result, _Allocator& __alloc)
314 _ForwardIterator __cur = __result;
318 for (; __first != __last; ++__first, (void)++__cur)
325 __throw_exception_again;
329 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp>
330 inline _ForwardIterator
331 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
332 _ForwardIterator __result, allocator<_Tp>&)
335 template<
typename _InputIterator,
typename _ForwardIterator,
337 inline _ForwardIterator
338 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
339 _ForwardIterator __result, _Allocator& __alloc)
341 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
342 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
346 template<
typename _InputIterator,
typename _ForwardIterator,
348 inline _ForwardIterator
349 __uninitialized_move_if_noexcept_a(_InputIterator __first,
350 _InputIterator __last,
351 _ForwardIterator __result,
354 return std::__uninitialized_copy_a
355 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
356 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
359 template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
361 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
362 const _Tp& __x, _Allocator& __alloc)
364 _ForwardIterator __cur = __first;
368 for (; __cur != __last; ++__cur)
374 __throw_exception_again;
378 template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
380 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
381 const _Tp& __x, allocator<_Tp2>&)
384 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
387 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
388 const _Tp& __x, _Allocator& __alloc)
390 _ForwardIterator __cur = __first;
394 for (; __n > 0; --__n, (void) ++__cur)
401 __throw_exception_again;
405 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
407 inline _ForwardIterator
408 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
409 const _Tp& __x, allocator<_Tp2>&)
422 template<
typename _InputIterator1,
typename _InputIterator2,
423 typename _ForwardIterator,
typename _Allocator>
424 inline _ForwardIterator
425 __uninitialized_copy_move(_InputIterator1 __first1,
426 _InputIterator1 __last1,
427 _InputIterator2 __first2,
428 _InputIterator2 __last2,
429 _ForwardIterator __result,
432 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
437 return std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
442 __throw_exception_again;
450 template<
typename _InputIterator1,
typename _InputIterator2,
451 typename _ForwardIterator,
typename _Allocator>
452 inline _ForwardIterator
453 __uninitialized_move_copy(_InputIterator1 __first1,
454 _InputIterator1 __last1,
455 _InputIterator2 __first2,
456 _InputIterator2 __last2,
457 _ForwardIterator __result,
460 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
465 return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
470 __throw_exception_again;
477 template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
479 inline _ForwardIterator
480 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
481 const _Tp& __x, _InputIterator __first,
482 _InputIterator __last, _Allocator& __alloc)
484 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
487 return std::__uninitialized_move_a(__first, __last, __mid, __alloc);
492 __throw_exception_again;
499 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
502 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
503 _ForwardIterator __first2,
504 _ForwardIterator __last2,
const _Tp& __x,
507 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
512 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
517 __throw_exception_again;
523#if __cplusplus >= 201103L
529 template<
bool _TrivialValueType>
530 struct __uninitialized_default_1
532 template<
typename _ForwardIterator>
534 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
536 _ForwardIterator __cur = __first;
539 for (; __cur != __last; ++__cur)
545 __throw_exception_again;
551 struct __uninitialized_default_1<true>
553 template<
typename _ForwardIterator>
555 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
557 if (__first == __last)
560 typename iterator_traits<_ForwardIterator>::value_type* __val
563 if (++__first != __last)
564 std::fill(__first, __last, *__val);
568 template<
bool _TrivialValueType>
569 struct __uninitialized_default_n_1
571 template<
typename _ForwardIterator,
typename _Size>
572 static _ForwardIterator
573 __uninit_default_n(_ForwardIterator __first, _Size __n)
575 _ForwardIterator __cur = __first;
578 for (; __n > 0; --__n, (void) ++__cur)
585 __throw_exception_again;
591 struct __uninitialized_default_n_1<true>
593 template<
typename _ForwardIterator,
typename _Size>
594 static _ForwardIterator
595 __uninit_default_n(_ForwardIterator __first, _Size __n)
599 typename iterator_traits<_ForwardIterator>::value_type* __val
603 __first = std::fill_n(__first, __n - 1, *__val);
611 template<
typename _ForwardIterator>
613 __uninitialized_default(_ForwardIterator __first,
614 _ForwardIterator __last)
616 typedef typename iterator_traits<_ForwardIterator>::value_type
619 const bool __assignable = is_copy_assignable<_ValueType>::value;
621 std::__uninitialized_default_1<__is_trivial(_ValueType)
623 __uninit_default(__first, __last);
628 template<
typename _ForwardIterator,
typename _Size>
629 inline _ForwardIterator
630 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
632 typedef typename iterator_traits<_ForwardIterator>::value_type
635 constexpr bool __can_fill
636 = __and_<is_integral<_Size>, is_copy_assignable<_ValueType>>::value;
638 return __uninitialized_default_n_1<__is_trivial(_ValueType)
640 __uninit_default_n(__first, __n);
647 template<
typename _ForwardIterator,
typename _Allocator>
649 __uninitialized_default_a(_ForwardIterator __first,
650 _ForwardIterator __last,
653 _ForwardIterator __cur = __first;
657 for (; __cur != __last; ++__cur)
663 __throw_exception_again;
667 template<
typename _ForwardIterator,
typename _Tp>
669 __uninitialized_default_a(_ForwardIterator __first,
670 _ForwardIterator __last,
672 { std::__uninitialized_default(__first, __last); }
678 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
680 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
683 _ForwardIterator __cur = __first;
687 for (; __n > 0; --__n, (void) ++__cur)
694 __throw_exception_again;
700 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
701 inline _ForwardIterator
702 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
704 {
return std::__uninitialized_default_n(__first, __n); }
706 template<
bool _TrivialValueType>
707 struct __uninitialized_default_novalue_1
709 template<
typename _ForwardIterator>
711 __uninit_default_novalue(_ForwardIterator __first,
712 _ForwardIterator __last)
714 _ForwardIterator __cur = __first;
717 for (; __cur != __last; ++__cur)
723 __throw_exception_again;
729 struct __uninitialized_default_novalue_1<true>
731 template<
typename _ForwardIterator>
733 __uninit_default_novalue(_ForwardIterator __first,
734 _ForwardIterator __last)
739 template<
bool _TrivialValueType>
740 struct __uninitialized_default_novalue_n_1
742 template<
typename _ForwardIterator,
typename _Size>
743 static _ForwardIterator
744 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
746 _ForwardIterator __cur = __first;
749 for (; __n > 0; --__n, (void) ++__cur)
756 __throw_exception_again;
762 struct __uninitialized_default_novalue_n_1<true>
764 template<
typename _ForwardIterator,
typename _Size>
765 static _ForwardIterator
766 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
767 {
return std::next(__first, __n); }
772 template<
typename _ForwardIterator>
774 __uninitialized_default_novalue(_ForwardIterator __first,
775 _ForwardIterator __last)
777 typedef typename iterator_traits<_ForwardIterator>::value_type
780 std::__uninitialized_default_novalue_1<
781 is_trivially_default_constructible<_ValueType>::value>::
782 __uninit_default_novalue(__first, __last);
787 template<
typename _ForwardIterator,
typename _Size>
788 inline _ForwardIterator
789 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
791 typedef typename iterator_traits<_ForwardIterator>::value_type
794 return __uninitialized_default_novalue_n_1<
795 is_trivially_default_constructible<_ValueType>::value>::
796 __uninit_default_novalue_n(__first, __n);
799 template<
typename _InputIterator,
typename _Size,
800 typename _ForwardIterator>
802 __uninitialized_copy_n(_InputIterator __first, _Size __n,
803 _ForwardIterator __result, input_iterator_tag)
805 _ForwardIterator __cur = __result;
808 for (; __n > 0; --__n, (void) ++__first, ++__cur)
815 __throw_exception_again;
819 template<
typename _RandomAccessIterator,
typename _Size,
820 typename _ForwardIterator>
821 inline _ForwardIterator
822 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
823 _ForwardIterator __result,
824 random_access_iterator_tag)
827 template<
typename _InputIterator,
typename _Size,
828 typename _ForwardIterator>
829 pair<_InputIterator, _ForwardIterator>
830 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
831 _ForwardIterator __result, input_iterator_tag)
833 _ForwardIterator __cur = __result;
836 for (; __n > 0; --__n, (void) ++__first, ++__cur)
838 return {__first, __cur};
843 __throw_exception_again;
847 template<
typename _RandomAccessIterator,
typename _Size,
848 typename _ForwardIterator>
849 inline pair<_RandomAccessIterator, _ForwardIterator>
850 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
851 _ForwardIterator __result,
852 random_access_iterator_tag)
855 auto __first_res = std::next(__first, __n);
856 return {__first_res, __second_res};
870 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
871 inline _ForwardIterator
873 _ForwardIterator __result)
874 {
return std::__uninitialized_copy_n(__first, __n, __result,
878 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
879 inline pair<_InputIterator, _ForwardIterator>
880 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
881 _ForwardIterator __result)
884 std::__uninitialized_copy_n_pair(__first, __n, __result,
890#if __cplusplus >= 201703L
891# define __cpp_lib_raw_memory_algorithms 201606L
898 template <
typename _ForwardIterator>
901 _ForwardIterator __last)
903 __uninitialized_default_novalue(__first, __last);
912 template <
typename _ForwardIterator,
typename _Size>
913 inline _ForwardIterator
916 return __uninitialized_default_novalue_n(__first, __count);
924 template <
typename _ForwardIterator>
927 _ForwardIterator __last)
929 return __uninitialized_default(__first, __last);
938 template <
typename _ForwardIterator,
typename _Size>
939 inline _ForwardIterator
942 return __uninitialized_default_n(__first, __count);
952 template <
typename _InputIterator,
typename _ForwardIterator>
953 inline _ForwardIterator
955 _ForwardIterator __result)
958 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
959 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
969 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
970 inline pair<_InputIterator, _ForwardIterator>
972 _ForwardIterator __result)
974 auto __res = std::__uninitialized_copy_n_pair
975 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
977 return {__res.first.base(), __res.second};
981#if __cplusplus >= 201103L
984 template<
typename _Tp,
typename _Up,
typename _Allocator>
986 __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig,
994 __traits::construct(__alloc, __dest,
std::move(*__orig));
1000 template<
typename _Tp,
typename =
void>
1001 struct __is_bitwise_relocatable
1002 : is_trivial<_Tp> { };
1004 template <
typename _Tp,
typename _Up>
1005 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
1006 __relocate_a_1(_Tp* __first, _Tp* __last,
1007 _Tp* __result, allocator<_Up>&)
noexcept
1009 ptrdiff_t __count = __last - __first;
1011 __builtin_memmove(__result, __first, __count *
sizeof(_Tp));
1012 return __result + __count;
1015 template <
typename _InputIterator,
typename _ForwardIterator,
1016 typename _Allocator>
1017 inline _ForwardIterator
1018 __relocate_a_1(_InputIterator __first, _InputIterator __last,
1019 _ForwardIterator __result, _Allocator& __alloc)
1020 noexcept(
noexcept(std::__relocate_object_a(
std::addressof(*__result),
1024 typedef typename iterator_traits<_InputIterator>::value_type
1026 typedef typename iterator_traits<_ForwardIterator>::value_type
1029 "relocation is only possible for values of the same type");
1030 _ForwardIterator __cur = __result;
1031 for (; __first != __last; ++__first, (void)++__cur)
1037 template <
typename _InputIterator,
typename _ForwardIterator,
1038 typename _Allocator>
1039 inline _ForwardIterator
1040 __relocate_a(_InputIterator __first, _InputIterator __last,
1041 _ForwardIterator __result, _Allocator& __alloc)
1042 noexcept(
noexcept(__relocate_a_1(std::__niter_base(__first),
1043 std::__niter_base(__last),
1044 std::__niter_base(__result), __alloc)))
1046 return __relocate_a_1(std::__niter_base(__first),
1047 std::__niter_base(__last),
1048 std::__niter_base(__result), __alloc);
1056_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 * 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)
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.