56 #ifndef _STL_UNINITIALIZED_H
57 #define _STL_UNINITIALIZED_H 1
59 #if __cplusplus > 201402L
63 #if __cplusplus >= 201103L
69 namespace std _GLIBCXX_VISIBILITY(default)
71 _GLIBCXX_BEGIN_NAMESPACE_VERSION
79 template<
bool _TrivialValueTypes>
80 struct __uninitialized_copy
82 template<
typename _InputIterator,
typename _ForwardIterator>
83 static _ForwardIterator
84 __uninit_copy(_InputIterator __first, _InputIterator __last,
85 _ForwardIterator __result)
87 _ForwardIterator __cur = __result;
90 for (; __first != __last; ++__first, (void)++__cur)
97 __throw_exception_again;
103 struct __uninitialized_copy<true>
105 template<
typename _InputIterator,
typename _ForwardIterator>
106 static _ForwardIterator
107 __uninit_copy(_InputIterator __first, _InputIterator __last,
108 _ForwardIterator __result)
109 {
return std::copy(__first, __last, __result); }
123 template<
typename _InputIterator,
typename _ForwardIterator>
124 inline _ForwardIterator
126 _ForwardIterator __result)
132 #if __cplusplus < 201103L
133 const bool __assignable =
true;
138 "result type must be constructible from value type of input range");
147 return std::__uninitialized_copy<__is_trivial(_ValueType1)
148 && __is_trivial(_ValueType2)
150 __uninit_copy(__first, __last, __result);
155 template<
bool _TrivialValueType>
156 struct __uninitialized_fill
158 template<
typename _ForwardIterator,
typename _Tp>
160 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
163 _ForwardIterator __cur = __first;
166 for (; __cur != __last; ++__cur)
172 __throw_exception_again;
178 struct __uninitialized_fill<true>
180 template<
typename _ForwardIterator,
typename _Tp>
182 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
184 { std::fill(__first, __last, __x); }
198 template<
typename _ForwardIterator,
typename _Tp>
205 #if __cplusplus < 201103L
206 const bool __assignable =
true;
211 "result type must be constructible from input type");
218 std::__uninitialized_fill<__is_trivial(_ValueType) && __assignable>::
219 __uninit_fill(__first, __last, __x);
224 template<
bool _TrivialValueType>
225 struct __uninitialized_fill_n
227 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
228 static _ForwardIterator
229 __uninit_fill_n(_ForwardIterator __first, _Size __n,
232 _ForwardIterator __cur = __first;
235 for (; __n > 0; --__n, (void) ++__cur)
242 __throw_exception_again;
248 struct __uninitialized_fill_n<true>
250 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
251 static _ForwardIterator
252 __uninit_fill_n(_ForwardIterator __first, _Size __n,
270 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
271 inline _ForwardIterator
276 #if __cplusplus < 201103L
277 const bool __assignable =
true;
282 "result type must be constructible from input type");
288 return __uninitialized_fill_n<__is_trivial(_ValueType) && __assignable>::
289 __uninit_fill_n(__first, __n, __x);
300 template<
typename _InputIterator,
typename _ForwardIterator,
303 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
304 _ForwardIterator __result, _Allocator& __alloc)
306 _ForwardIterator __cur = __result;
310 for (; __first != __last; ++__first, (void)++__cur)
317 __throw_exception_again;
321 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp>
322 inline _ForwardIterator
323 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
324 _ForwardIterator __result, allocator<_Tp>&)
327 template<
typename _InputIterator,
typename _ForwardIterator,
329 inline _ForwardIterator
330 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
331 _ForwardIterator __result, _Allocator& __alloc)
333 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
334 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
338 template<
typename _InputIterator,
typename _ForwardIterator,
340 inline _ForwardIterator
341 __uninitialized_move_if_noexcept_a(_InputIterator __first,
342 _InputIterator __last,
343 _ForwardIterator __result,
346 return std::__uninitialized_copy_a
347 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
348 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
351 template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
353 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
354 const _Tp& __x, _Allocator& __alloc)
356 _ForwardIterator __cur = __first;
360 for (; __cur != __last; ++__cur)
366 __throw_exception_again;
370 template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
372 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
373 const _Tp& __x, allocator<_Tp2>&)
376 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
379 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
380 const _Tp& __x, _Allocator& __alloc)
382 _ForwardIterator __cur = __first;
386 for (; __n > 0; --__n, (void) ++__cur)
393 __throw_exception_again;
397 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
399 inline _ForwardIterator
400 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
401 const _Tp& __x, allocator<_Tp2>&)
414 template<
typename _InputIterator1,
typename _InputIterator2,
415 typename _ForwardIterator,
typename _Allocator>
416 inline _ForwardIterator
417 __uninitialized_copy_move(_InputIterator1 __first1,
418 _InputIterator1 __last1,
419 _InputIterator2 __first2,
420 _InputIterator2 __last2,
421 _ForwardIterator __result,
424 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
429 return std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
434 __throw_exception_again;
442 template<
typename _InputIterator1,
typename _InputIterator2,
443 typename _ForwardIterator,
typename _Allocator>
444 inline _ForwardIterator
445 __uninitialized_move_copy(_InputIterator1 __first1,
446 _InputIterator1 __last1,
447 _InputIterator2 __first2,
448 _InputIterator2 __last2,
449 _ForwardIterator __result,
452 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
457 return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
462 __throw_exception_again;
469 template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
471 inline _ForwardIterator
472 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
473 const _Tp& __x, _InputIterator __first,
474 _InputIterator __last, _Allocator& __alloc)
476 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
479 return std::__uninitialized_move_a(__first, __last, __mid, __alloc);
484 __throw_exception_again;
491 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
494 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
495 _ForwardIterator __first2,
496 _ForwardIterator __last2,
const _Tp& __x,
499 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
504 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
509 __throw_exception_again;
515 #if __cplusplus >= 201103L
521 template<
bool _TrivialValueType>
522 struct __uninitialized_default_1
524 template<
typename _ForwardIterator>
526 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
528 _ForwardIterator __cur = __first;
531 for (; __cur != __last; ++__cur)
537 __throw_exception_again;
543 struct __uninitialized_default_1<true>
545 template<
typename _ForwardIterator>
547 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
549 typedef typename iterator_traits<_ForwardIterator>::value_type
552 if (__first == __last)
555 typename iterator_traits<_ForwardIterator>::value_type* __val
558 if (++__first != __last)
559 std::fill(__first, __last, *__val);
563 template<
bool _TrivialValueType>
564 struct __uninitialized_default_n_1
566 template<
typename _ForwardIterator,
typename _Size>
567 static _ForwardIterator
568 __uninit_default_n(_ForwardIterator __first, _Size __n)
570 _ForwardIterator __cur = __first;
573 for (; __n > 0; --__n, (void) ++__cur)
580 __throw_exception_again;
586 struct __uninitialized_default_n_1<true>
588 template<
typename _ForwardIterator,
typename _Size>
589 static _ForwardIterator
590 __uninit_default_n(_ForwardIterator __first, _Size __n)
594 typename iterator_traits<_ForwardIterator>::value_type* __val
606 template<
typename _ForwardIterator>
608 __uninitialized_default(_ForwardIterator __first,
609 _ForwardIterator __last)
611 typedef typename iterator_traits<_ForwardIterator>::value_type
614 const bool __assignable = is_copy_assignable<_ValueType>::value;
616 std::__uninitialized_default_1<__is_trivial(_ValueType)
618 __uninit_default(__first, __last);
623 template<
typename _ForwardIterator,
typename _Size>
624 inline _ForwardIterator
625 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
627 typedef typename iterator_traits<_ForwardIterator>::value_type
630 const bool __assignable = is_copy_assignable<_ValueType>::value;
632 return __uninitialized_default_n_1<__is_trivial(_ValueType)
634 __uninit_default_n(__first, __n);
641 template<
typename _ForwardIterator,
typename _Allocator>
643 __uninitialized_default_a(_ForwardIterator __first,
644 _ForwardIterator __last,
647 _ForwardIterator __cur = __first;
651 for (; __cur != __last; ++__cur)
657 __throw_exception_again;
661 template<
typename _ForwardIterator,
typename _Tp>
663 __uninitialized_default_a(_ForwardIterator __first,
664 _ForwardIterator __last,
666 { std::__uninitialized_default(__first, __last); }
672 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
674 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
677 _ForwardIterator __cur = __first;
681 for (; __n > 0; --__n, (void) ++__cur)
688 __throw_exception_again;
694 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
695 inline _ForwardIterator
696 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
698 {
return std::__uninitialized_default_n(__first, __n); }
700 template<
bool _TrivialValueType>
701 struct __uninitialized_default_novalue_1
703 template<
typename _ForwardIterator>
705 __uninit_default_novalue(_ForwardIterator __first,
706 _ForwardIterator __last)
708 _ForwardIterator __cur = __first;
711 for (; __cur != __last; ++__cur)
717 __throw_exception_again;
723 struct __uninitialized_default_novalue_1<true>
725 template<
typename _ForwardIterator>
727 __uninit_default_novalue(_ForwardIterator __first,
728 _ForwardIterator __last)
733 template<
bool _TrivialValueType>
734 struct __uninitialized_default_novalue_n_1
736 template<
typename _ForwardIterator,
typename _Size>
737 static _ForwardIterator
738 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
740 _ForwardIterator __cur = __first;
743 for (; __n > 0; --__n, (void) ++__cur)
750 __throw_exception_again;
756 struct __uninitialized_default_novalue_n_1<true>
758 template<
typename _ForwardIterator,
typename _Size>
759 static _ForwardIterator
760 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
761 {
return std::next(__first, __n); }
766 template<
typename _ForwardIterator>
768 __uninitialized_default_novalue(_ForwardIterator __first,
769 _ForwardIterator __last)
771 typedef typename iterator_traits<_ForwardIterator>::value_type
774 std::__uninitialized_default_novalue_1<
775 is_trivially_default_constructible<_ValueType>::value>::
776 __uninit_default_novalue(__first, __last);
781 template<
typename _ForwardIterator,
typename _Size>
782 inline _ForwardIterator
783 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
785 typedef typename iterator_traits<_ForwardIterator>::value_type
788 return __uninitialized_default_novalue_n_1<
789 is_trivially_default_constructible<_ValueType>::value>::
790 __uninit_default_novalue_n(__first, __n);
793 template<
typename _InputIterator,
typename _Size,
794 typename _ForwardIterator>
796 __uninitialized_copy_n(_InputIterator __first, _Size __n,
797 _ForwardIterator __result, input_iterator_tag)
799 _ForwardIterator __cur = __result;
802 for (; __n > 0; --__n, (void) ++__first, ++__cur)
809 __throw_exception_again;
813 template<
typename _RandomAccessIterator,
typename _Size,
814 typename _ForwardIterator>
815 inline _ForwardIterator
816 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
817 _ForwardIterator __result,
818 random_access_iterator_tag)
821 template<
typename _InputIterator,
typename _Size,
822 typename _ForwardIterator>
823 pair<_InputIterator, _ForwardIterator>
824 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
825 _ForwardIterator __result, input_iterator_tag)
827 _ForwardIterator __cur = __result;
830 for (; __n > 0; --__n, (void) ++__first, ++__cur)
832 return {__first, __cur};
837 __throw_exception_again;
841 template<
typename _RandomAccessIterator,
typename _Size,
842 typename _ForwardIterator>
843 inline pair<_RandomAccessIterator, _ForwardIterator>
844 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
845 _ForwardIterator __result,
846 random_access_iterator_tag)
849 auto __first_res = std::next(__first, __n);
850 return {__first_res, __second_res};
864 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
865 inline _ForwardIterator
867 _ForwardIterator __result)
868 {
return std::__uninitialized_copy_n(__first, __n, __result,
872 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
873 inline pair<_InputIterator, _ForwardIterator>
874 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
875 _ForwardIterator __result)
878 std::__uninitialized_copy_n_pair(__first, __n, __result,
884 #if __cplusplus >= 201703L
885 # define __cpp_lib_raw_memory_algorithms 201606L
892 template <
typename _ForwardIterator>
894 uninitialized_default_construct(_ForwardIterator __first,
895 _ForwardIterator __last)
897 __uninitialized_default_novalue(__first, __last);
906 template <
typename _ForwardIterator,
typename _Size>
907 inline _ForwardIterator
908 uninitialized_default_construct_n(_ForwardIterator __first, _Size __count)
910 return __uninitialized_default_novalue_n(__first, __count);
918 template <
typename _ForwardIterator>
920 uninitialized_value_construct(_ForwardIterator __first,
921 _ForwardIterator __last)
923 return __uninitialized_default(__first, __last);
932 template <
typename _ForwardIterator,
typename _Size>
933 inline _ForwardIterator
934 uninitialized_value_construct_n(_ForwardIterator __first, _Size __count)
936 return __uninitialized_default_n(__first, __count);
946 template <
typename _InputIterator,
typename _ForwardIterator>
947 inline _ForwardIterator
948 uninitialized_move(_InputIterator __first, _InputIterator __last,
949 _ForwardIterator __result)
952 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
953 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
963 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
964 inline pair<_InputIterator, _ForwardIterator>
965 uninitialized_move_n(_InputIterator __first, _Size __count,
966 _ForwardIterator __result)
968 auto __res = std::__uninitialized_copy_n_pair
969 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
971 return {__res.first.base(), __res.second};
975 #if __cplusplus >= 201103L
978 template<
typename _Tp,
typename _Up,
typename _Allocator>
980 __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig,
988 __traits::construct(__alloc, __dest,
std::move(*__orig));
994 template<
typename _Tp,
typename =
void>
995 struct __is_bitwise_relocatable
996 : is_trivial<_Tp> { };
998 template <
typename _Tp,
typename _Up>
999 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
1000 __relocate_a_1(_Tp* __first, _Tp* __last,
1001 _Tp* __result, allocator<_Up>&) noexcept
1003 ptrdiff_t __count = __last - __first;
1005 __builtin_memmove(__result, __first, __count *
sizeof(_Tp));
1006 return __result + __count;
1009 template <
typename _InputIterator,
typename _ForwardIterator,
1010 typename _Allocator>
1011 inline _ForwardIterator
1012 __relocate_a_1(_InputIterator __first, _InputIterator __last,
1013 _ForwardIterator __result, _Allocator& __alloc)
1014 noexcept(noexcept(std::__relocate_object_a(
std::addressof(*__result),
1018 typedef typename iterator_traits<_InputIterator>::value_type
1020 typedef typename iterator_traits<_ForwardIterator>::value_type
1023 "relocation is only possible for values of the same type");
1024 _ForwardIterator __cur = __result;
1025 for (; __first != __last; ++__first, (void)++__cur)
1031 template <
typename _InputIterator,
typename _ForwardIterator,
1032 typename _Allocator>
1033 inline _ForwardIterator
1034 __relocate_a(_InputIterator __first, _InputIterator __last,
1035 _ForwardIterator __result, _Allocator& __alloc)
1036 noexcept(noexcept(__relocate_a_1(std::__niter_base(__first),
1037 std::__niter_base(__last),
1038 std::__niter_base(__result), __alloc)))
1040 return __relocate_a_1(std::__niter_base(__first),
1041 std::__niter_base(__last),
1042 std::__niter_base(__result), __alloc);
1050 _GLIBCXX_END_NAMESPACE_VERSION
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 _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
_ForwardIterator uninitialized_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result)
Copies the range [first,last) into result.
Uniform interface to C++98 and C++11 allocators.
constexpr _OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
_ForwardIterator uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp &__x)
Copies the value x into the range [first,first+n).
Uniform interface to all allocator types.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
void _Construct(_Tp *__p, _Args &&...__args)
void uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__x)
Copies the value x into the range [first,last).
_ForwardIterator uninitialized_copy_n(_InputIterator __first, _Size __n, _ForwardIterator __result)
Copies the range [first,first+n) into result.
void _Destroy(_ForwardIterator __first, _ForwardIterator __last, _Allocator &__alloc)
Traits class for iterators.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.