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,
254 {
return std::fill_n(__first, __n, __x); }
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 std::fill(__first, __last, _ValueType());
556 template<
bool _TrivialValueType>
557 struct __uninitialized_default_n_1
559 template<
typename _ForwardIterator,
typename _Size>
560 static _ForwardIterator
561 __uninit_default_n(_ForwardIterator __first, _Size __n)
563 _ForwardIterator __cur = __first;
566 for (; __n > 0; --__n, (void) ++__cur)
573 __throw_exception_again;
579 struct __uninitialized_default_n_1<true>
581 template<
typename _ForwardIterator,
typename _Size>
582 static _ForwardIterator
583 __uninit_default_n(_ForwardIterator __first, _Size __n)
585 typedef typename iterator_traits<_ForwardIterator>::value_type
588 return std::fill_n(__first, __n, _ValueType());
595 template<
typename _ForwardIterator>
597 __uninitialized_default(_ForwardIterator __first,
598 _ForwardIterator __last)
600 typedef typename iterator_traits<_ForwardIterator>::value_type
603 const bool __assignable = is_copy_assignable<_ValueType>::value;
605 std::__uninitialized_default_1<__is_trivial(_ValueType)
607 __uninit_default(__first, __last);
612 template<
typename _ForwardIterator,
typename _Size>
613 inline _ForwardIterator
614 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
616 typedef typename iterator_traits<_ForwardIterator>::value_type
619 const bool __assignable = is_copy_assignable<_ValueType>::value;
621 return __uninitialized_default_n_1<__is_trivial(_ValueType)
623 __uninit_default_n(__first, __n);
630 template<
typename _ForwardIterator,
typename _Allocator>
632 __uninitialized_default_a(_ForwardIterator __first,
633 _ForwardIterator __last,
636 _ForwardIterator __cur = __first;
640 for (; __cur != __last; ++__cur)
646 __throw_exception_again;
650 template<
typename _ForwardIterator,
typename _Tp>
652 __uninitialized_default_a(_ForwardIterator __first,
653 _ForwardIterator __last,
655 { std::__uninitialized_default(__first, __last); }
661 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
663 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
666 _ForwardIterator __cur = __first;
670 for (; __n > 0; --__n, (void) ++__cur)
677 __throw_exception_again;
681 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
682 inline _ForwardIterator
683 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
685 {
return std::__uninitialized_default_n(__first, __n); }
687 template<
bool _TrivialValueType>
688 struct __uninitialized_default_novalue_1
690 template<
typename _ForwardIterator>
692 __uninit_default_novalue(_ForwardIterator __first,
693 _ForwardIterator __last)
695 _ForwardIterator __cur = __first;
698 for (; __cur != __last; ++__cur)
704 __throw_exception_again;
710 struct __uninitialized_default_novalue_1<true>
712 template<
typename _ForwardIterator>
714 __uninit_default_novalue(_ForwardIterator __first,
715 _ForwardIterator __last)
720 template<
bool _TrivialValueType>
721 struct __uninitialized_default_novalue_n_1
723 template<
typename _ForwardIterator,
typename _Size>
724 static _ForwardIterator
725 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
727 _ForwardIterator __cur = __first;
730 for (; __n > 0; --__n, (void) ++__cur)
737 __throw_exception_again;
743 struct __uninitialized_default_novalue_n_1<true>
745 template<
typename _ForwardIterator,
typename _Size>
746 static _ForwardIterator
747 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
748 {
return std::next(__first, __n); }
754 template<
typename _ForwardIterator>
756 __uninitialized_default_novalue(_ForwardIterator __first,
757 _ForwardIterator __last)
759 typedef typename iterator_traits<_ForwardIterator>::value_type
762 std::__uninitialized_default_novalue_1<
763 is_trivially_default_constructible<_ValueType>::value>::
764 __uninit_default_novalue(__first, __last);
769 template<
typename _ForwardIterator,
typename _Size>
770 inline _ForwardIterator
771 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
773 typedef typename iterator_traits<_ForwardIterator>::value_type
776 return __uninitialized_default_novalue_n_1<
777 is_trivially_default_constructible<_ValueType>::value>::
778 __uninit_default_novalue_n(__first, __n);
781 template<
typename _InputIterator,
typename _Size,
782 typename _ForwardIterator>
784 __uninitialized_copy_n(_InputIterator __first, _Size __n,
785 _ForwardIterator __result, input_iterator_tag)
787 _ForwardIterator __cur = __result;
790 for (; __n > 0; --__n, (void) ++__first, ++__cur)
797 __throw_exception_again;
801 template<
typename _RandomAccessIterator,
typename _Size,
802 typename _ForwardIterator>
803 inline _ForwardIterator
804 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
805 _ForwardIterator __result,
806 random_access_iterator_tag)
809 template<
typename _InputIterator,
typename _Size,
810 typename _ForwardIterator>
811 pair<_InputIterator, _ForwardIterator>
812 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
813 _ForwardIterator __result, input_iterator_tag)
815 _ForwardIterator __cur = __result;
818 for (; __n > 0; --__n, (void) ++__first, ++__cur)
820 return {__first, __cur};
825 __throw_exception_again;
829 template<
typename _RandomAccessIterator,
typename _Size,
830 typename _ForwardIterator>
831 inline pair<_RandomAccessIterator, _ForwardIterator>
832 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
833 _ForwardIterator __result,
834 random_access_iterator_tag)
837 auto __first_res = std::next(__first, __n);
838 return {__first_res, __second_res};
852 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
853 inline _ForwardIterator
855 _ForwardIterator __result)
856 {
return std::__uninitialized_copy_n(__first, __n, __result,
860 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
861 inline pair<_InputIterator, _ForwardIterator>
862 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
863 _ForwardIterator __result)
866 std::__uninitialized_copy_n_pair(__first, __n, __result,
872 #if __cplusplus >= 201703L
873 # define __cpp_lib_raw_memory_algorithms 201606L
880 template <
typename _ForwardIterator>
882 uninitialized_default_construct(_ForwardIterator __first,
883 _ForwardIterator __last)
885 __uninitialized_default_novalue(__first, __last);
894 template <
typename _ForwardIterator,
typename _Size>
895 inline _ForwardIterator
896 uninitialized_default_construct_n(_ForwardIterator __first, _Size __count)
898 return __uninitialized_default_novalue_n(__first, __count);
906 template <
typename _ForwardIterator>
908 uninitialized_value_construct(_ForwardIterator __first,
909 _ForwardIterator __last)
911 return __uninitialized_default(__first, __last);
920 template <
typename _ForwardIterator,
typename _Size>
921 inline _ForwardIterator
922 uninitialized_value_construct_n(_ForwardIterator __first, _Size __count)
924 return __uninitialized_default_n(__first, __count);
934 template <
typename _InputIterator,
typename _ForwardIterator>
935 inline _ForwardIterator
936 uninitialized_move(_InputIterator __first, _InputIterator __last,
937 _ForwardIterator __result)
940 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
941 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
951 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
952 inline pair<_InputIterator, _ForwardIterator>
953 uninitialized_move_n(_InputIterator __first, _Size __count,
954 _ForwardIterator __result)
956 auto __res = std::__uninitialized_copy_n_pair
957 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
959 return {__res.first.base(), __res.second};
963 #if __cplusplus >= 201103L
966 template<
typename _Tp,
typename _Up,
typename _Allocator>
968 __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig,
976 __traits::construct(__alloc, __dest,
std::move(*__orig));
982 template<
typename _Tp,
typename =
void>
983 struct __is_bitwise_relocatable
984 : is_trivial<_Tp> { };
986 template <
typename _Tp,
typename _Up>
987 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
988 __relocate_a_1(_Tp* __first, _Tp* __last,
989 _Tp* __result, allocator<_Up>&) noexcept
991 ptrdiff_t __count = __last - __first;
993 __builtin_memmove(__result, __first, __count *
sizeof(_Tp));
994 return __result + __count;
997 template <
typename _InputIterator,
typename _ForwardIterator,
999 inline _ForwardIterator
1000 __relocate_a_1(_InputIterator __first, _InputIterator __last,
1001 _ForwardIterator __result, _Allocator& __alloc)
1002 noexcept(noexcept(std::__relocate_object_a(
std::addressof(*__result),
1006 typedef typename iterator_traits<_InputIterator>::value_type
1008 typedef typename iterator_traits<_ForwardIterator>::value_type
1011 "relocation is only possible for values of the same type");
1012 _ForwardIterator __cur = __result;
1013 for (; __first != __last; ++__first, (void)++__cur)
1019 template <
typename _InputIterator,
typename _ForwardIterator,
1020 typename _Allocator>
1021 inline _ForwardIterator
1022 __relocate_a(_InputIterator __first, _InputIterator __last,
1023 _ForwardIterator __result, _Allocator& __alloc)
1024 noexcept(noexcept(__relocate_a_1(std::__niter_base(__first),
1025 std::__niter_base(__last),
1026 std::__niter_base(__result), __alloc)))
1028 return __relocate_a_1(std::__niter_base(__first),
1029 std::__niter_base(__last),
1030 std::__niter_base(__result), __alloc);
1038 _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_fill_n(_ForwardIterator __first, _Size __n, const _Tp &__x)
Copies the value x into the range [first,first+n).
_ForwardIterator uninitialized_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result)
Copies the range [first,last) into result.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
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 iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
ISO C++ entities toplevel namespace is std.
void _Construct(_Tp *__p, _Args &&... __args)
void _Destroy(_ForwardIterator __first, _ForwardIterator __last, _Allocator &__alloc)
Uniform interface to all allocator types.
Traits class for iterators.
Uniform interface to C++98 and C++11 allocators.