56 #ifndef _STL_UNINITIALIZED_H 57 #define _STL_UNINITIALIZED_H 1 59 #if __cplusplus > 201402L 63 #if __cplusplus >= 201103L 67 namespace std _GLIBCXX_VISIBILITY(default)
69 _GLIBCXX_BEGIN_NAMESPACE_VERSION
71 template<
bool _TrivialValueTypes>
72 struct __uninitialized_copy
74 template<
typename _InputIterator,
typename _ForwardIterator>
75 static _ForwardIterator
76 __uninit_copy(_InputIterator __first, _InputIterator __last,
77 _ForwardIterator __result)
79 _ForwardIterator __cur = __result;
82 for (; __first != __last; ++__first, (void)++__cur)
89 __throw_exception_again;
95 struct __uninitialized_copy<true>
97 template<
typename _InputIterator,
typename _ForwardIterator>
98 static _ForwardIterator
99 __uninit_copy(_InputIterator __first, _InputIterator __last,
100 _ForwardIterator __result)
101 {
return std::copy(__first, __last, __result); }
113 template<
typename _InputIterator,
typename _ForwardIterator>
114 inline _ForwardIterator
116 _ForwardIterator __result)
118 typedef typename iterator_traits<_InputIterator>::value_type
120 typedef typename iterator_traits<_ForwardIterator>::value_type
122 #if __cplusplus < 201103L 123 const bool __assignable =
true;
128 "result type must be constructible from value type of input range");
130 typedef typename iterator_traits<_InputIterator>::reference _RefType1;
131 typedef typename iterator_traits<_ForwardIterator>::reference _RefType2;
137 return std::__uninitialized_copy<__is_trivial(_ValueType1)
138 && __is_trivial(_ValueType2)
140 __uninit_copy(__first, __last, __result);
144 template<
bool _TrivialValueType>
145 struct __uninitialized_fill
147 template<
typename _ForwardIterator,
typename _Tp>
149 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
152 _ForwardIterator __cur = __first;
155 for (; __cur != __last; ++__cur)
161 __throw_exception_again;
167 struct __uninitialized_fill<true>
169 template<
typename _ForwardIterator,
typename _Tp>
171 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
173 { std::fill(__first, __last, __x); }
185 template<
typename _ForwardIterator,
typename _Tp>
190 typedef typename iterator_traits<_ForwardIterator>::value_type
192 #if __cplusplus < 201103L 193 const bool __assignable =
true;
198 "result type must be constructible from input type");
205 std::__uninitialized_fill<__is_trivial(_ValueType) && __assignable>::
206 __uninit_fill(__first, __last, __x);
210 template<
bool _TrivialValueType>
211 struct __uninitialized_fill_n
213 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
214 static _ForwardIterator
215 __uninit_fill_n(_ForwardIterator __first, _Size __n,
218 _ForwardIterator __cur = __first;
221 for (; __n > 0; --__n, (void) ++__cur)
228 __throw_exception_again;
234 struct __uninitialized_fill_n<true>
236 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
237 static _ForwardIterator
238 __uninit_fill_n(_ForwardIterator __first, _Size __n,
254 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
255 inline _ForwardIterator
258 typedef typename iterator_traits<_ForwardIterator>::value_type
260 #if __cplusplus < 201103L 261 const bool __assignable =
true;
266 "result type must be constructible from input type");
272 return __uninitialized_fill_n<__is_trivial(_ValueType) && __assignable>::
273 __uninit_fill_n(__first, __n, __x);
282 template<
typename _InputIterator,
typename _ForwardIterator,
285 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
286 _ForwardIterator __result, _Allocator& __alloc)
288 _ForwardIterator __cur = __result;
292 for (; __first != __last; ++__first, (void)++__cur)
299 __throw_exception_again;
303 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp>
304 inline _ForwardIterator
305 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
306 _ForwardIterator __result, allocator<_Tp>&)
309 template<
typename _InputIterator,
typename _ForwardIterator,
311 inline _ForwardIterator
312 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
313 _ForwardIterator __result, _Allocator& __alloc)
315 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
316 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
320 template<
typename _InputIterator,
typename _ForwardIterator,
322 inline _ForwardIterator
323 __uninitialized_move_if_noexcept_a(_InputIterator __first,
324 _InputIterator __last,
325 _ForwardIterator __result,
328 return std::__uninitialized_copy_a
329 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
330 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
333 template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
335 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
336 const _Tp& __x, _Allocator& __alloc)
338 _ForwardIterator __cur = __first;
342 for (; __cur != __last; ++__cur)
348 __throw_exception_again;
352 template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
354 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
355 const _Tp& __x, allocator<_Tp2>&)
358 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
361 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
362 const _Tp& __x, _Allocator& __alloc)
364 _ForwardIterator __cur = __first;
368 for (; __n > 0; --__n, (void) ++__cur)
375 __throw_exception_again;
379 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
381 inline _ForwardIterator
382 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
383 const _Tp& __x, allocator<_Tp2>&)
396 template<
typename _InputIterator1,
typename _InputIterator2,
397 typename _ForwardIterator,
typename _Allocator>
398 inline _ForwardIterator
399 __uninitialized_copy_move(_InputIterator1 __first1,
400 _InputIterator1 __last1,
401 _InputIterator2 __first2,
402 _InputIterator2 __last2,
403 _ForwardIterator __result,
406 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
411 return std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
416 __throw_exception_again;
424 template<
typename _InputIterator1,
typename _InputIterator2,
425 typename _ForwardIterator,
typename _Allocator>
426 inline _ForwardIterator
427 __uninitialized_move_copy(_InputIterator1 __first1,
428 _InputIterator1 __last1,
429 _InputIterator2 __first2,
430 _InputIterator2 __last2,
431 _ForwardIterator __result,
434 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
439 return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
444 __throw_exception_again;
451 template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
453 inline _ForwardIterator
454 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
455 const _Tp& __x, _InputIterator __first,
456 _InputIterator __last, _Allocator& __alloc)
458 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
461 return std::__uninitialized_move_a(__first, __last, __mid, __alloc);
466 __throw_exception_again;
473 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
476 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
477 _ForwardIterator __first2,
478 _ForwardIterator __last2,
const _Tp& __x,
481 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
486 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
491 __throw_exception_again;
495 #if __cplusplus >= 201103L 499 template<
bool _TrivialValueType>
500 struct __uninitialized_default_1
502 template<
typename _ForwardIterator>
504 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
506 _ForwardIterator __cur = __first;
509 for (; __cur != __last; ++__cur)
515 __throw_exception_again;
521 struct __uninitialized_default_1<true>
523 template<
typename _ForwardIterator>
525 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
527 typedef typename iterator_traits<_ForwardIterator>::value_type
530 std::fill(__first, __last, _ValueType());
534 template<
bool _TrivialValueType>
535 struct __uninitialized_default_n_1
537 template<
typename _ForwardIterator,
typename _Size>
538 static _ForwardIterator
539 __uninit_default_n(_ForwardIterator __first, _Size __n)
541 _ForwardIterator __cur = __first;
544 for (; __n > 0; --__n, (void) ++__cur)
551 __throw_exception_again;
557 struct __uninitialized_default_n_1<true>
559 template<
typename _ForwardIterator,
typename _Size>
560 static _ForwardIterator
561 __uninit_default_n(_ForwardIterator __first, _Size __n)
563 typedef typename iterator_traits<_ForwardIterator>::value_type
573 template<
typename _ForwardIterator>
575 __uninitialized_default(_ForwardIterator __first,
576 _ForwardIterator __last)
578 typedef typename iterator_traits<_ForwardIterator>::value_type
581 const bool __assignable = is_copy_assignable<_ValueType>::value;
583 std::__uninitialized_default_1<__is_trivial(_ValueType)
585 __uninit_default(__first, __last);
590 template<
typename _ForwardIterator,
typename _Size>
591 inline _ForwardIterator
592 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
594 typedef typename iterator_traits<_ForwardIterator>::value_type
597 const bool __assignable = is_copy_assignable<_ValueType>::value;
599 return __uninitialized_default_n_1<__is_trivial(_ValueType)
601 __uninit_default_n(__first, __n);
608 template<
typename _ForwardIterator,
typename _Allocator>
610 __uninitialized_default_a(_ForwardIterator __first,
611 _ForwardIterator __last,
614 _ForwardIterator __cur = __first;
618 for (; __cur != __last; ++__cur)
624 __throw_exception_again;
628 template<
typename _ForwardIterator,
typename _Tp>
630 __uninitialized_default_a(_ForwardIterator __first,
631 _ForwardIterator __last,
633 { std::__uninitialized_default(__first, __last); }
639 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
641 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
644 _ForwardIterator __cur = __first;
648 for (; __n > 0; --__n, (void) ++__cur)
655 __throw_exception_again;
659 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
660 inline _ForwardIterator
661 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
663 {
return std::__uninitialized_default_n(__first, __n); }
665 template<
bool _TrivialValueType>
666 struct __uninitialized_default_novalue_1
668 template<
typename _ForwardIterator>
670 __uninit_default_novalue(_ForwardIterator __first,
671 _ForwardIterator __last)
673 _ForwardIterator __cur = __first;
676 for (; __cur != __last; ++__cur)
682 __throw_exception_again;
688 struct __uninitialized_default_novalue_1<true>
690 template<
typename _ForwardIterator>
692 __uninit_default_novalue(_ForwardIterator __first,
693 _ForwardIterator __last)
698 template<
bool _TrivialValueType>
699 struct __uninitialized_default_novalue_n_1
701 template<
typename _ForwardIterator,
typename _Size>
702 static _ForwardIterator
703 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
705 _ForwardIterator __cur = __first;
708 for (; __n > 0; --__n, (void) ++__cur)
715 __throw_exception_again;
721 struct __uninitialized_default_novalue_n_1<true>
723 template<
typename _ForwardIterator,
typename _Size>
724 static _ForwardIterator
725 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
726 {
return std::next(__first, __n); }
732 template<
typename _ForwardIterator>
734 __uninitialized_default_novalue(_ForwardIterator __first,
735 _ForwardIterator __last)
737 typedef typename iterator_traits<_ForwardIterator>::value_type
740 std::__uninitialized_default_novalue_1<
741 is_trivially_default_constructible<_ValueType>::value>::
742 __uninit_default_novalue(__first, __last);
747 template<
typename _ForwardIterator,
typename _Size>
748 inline _ForwardIterator
749 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
751 typedef typename iterator_traits<_ForwardIterator>::value_type
754 return __uninitialized_default_novalue_n_1<
755 is_trivially_default_constructible<_ValueType>::value>::
756 __uninit_default_novalue_n(__first, __n);
759 template<
typename _InputIterator,
typename _Size,
760 typename _ForwardIterator>
762 __uninitialized_copy_n(_InputIterator __first, _Size __n,
763 _ForwardIterator __result, input_iterator_tag)
765 _ForwardIterator __cur = __result;
768 for (; __n > 0; --__n, (void) ++__first, ++__cur)
775 __throw_exception_again;
779 template<
typename _RandomAccessIterator,
typename _Size,
780 typename _ForwardIterator>
781 inline _ForwardIterator
782 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
783 _ForwardIterator __result,
784 random_access_iterator_tag)
787 template<
typename _InputIterator,
typename _Size,
788 typename _ForwardIterator>
789 pair<_InputIterator, _ForwardIterator>
790 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
791 _ForwardIterator __result, input_iterator_tag)
793 _ForwardIterator __cur = __result;
796 for (; __n > 0; --__n, (void) ++__first, ++__cur)
798 return {__first, __cur};
803 __throw_exception_again;
807 template<
typename _RandomAccessIterator,
typename _Size,
808 typename _ForwardIterator>
809 inline pair<_RandomAccessIterator, _ForwardIterator>
810 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
811 _ForwardIterator __result,
812 random_access_iterator_tag)
815 auto __first_res = std::next(__first, __n);
816 return {__first_res, __second_res};
828 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
829 inline _ForwardIterator
831 _ForwardIterator __result)
832 {
return std::__uninitialized_copy_n(__first, __n, __result,
835 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
836 inline pair<_InputIterator, _ForwardIterator>
837 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
838 _ForwardIterator __result)
841 std::__uninitialized_copy_n_pair(__first, __n, __result,
847 #if __cplusplus >= 201703L 848 # define __cpp_lib_raw_memory_algorithms 201606L 850 template <
typename _ForwardIterator>
852 uninitialized_default_construct(_ForwardIterator __first,
853 _ForwardIterator __last)
855 __uninitialized_default_novalue(__first, __last);
858 template <
typename _ForwardIterator,
typename _Size>
859 inline _ForwardIterator
860 uninitialized_default_construct_n(_ForwardIterator __first, _Size __count)
862 return __uninitialized_default_novalue_n(__first, __count);
865 template <
typename _ForwardIterator>
867 uninitialized_value_construct(_ForwardIterator __first,
868 _ForwardIterator __last)
870 return __uninitialized_default(__first, __last);
873 template <
typename _ForwardIterator,
typename _Size>
874 inline _ForwardIterator
875 uninitialized_value_construct_n(_ForwardIterator __first, _Size __count)
877 return __uninitialized_default_n(__first, __count);
880 template <
typename _InputIterator,
typename _ForwardIterator>
881 inline _ForwardIterator
882 uninitialized_move(_InputIterator __first, _InputIterator __last,
883 _ForwardIterator __result)
886 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
887 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
890 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
891 inline pair<_InputIterator, _ForwardIterator>
892 uninitialized_move_n(_InputIterator __first, _Size __count,
893 _ForwardIterator __result)
895 auto __res = std::__uninitialized_copy_n_pair
896 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
898 return {__res.first.base(), __res.second};
902 #if __cplusplus >= 201103L 903 template<
typename _Tp,
typename _Up,
typename _Allocator>
905 __relocate_object_a(_Tp* __dest, _Up* __orig, _Allocator& __alloc)
907 __dest, std::move(*__orig)))
912 __traits::construct(__alloc, __dest, std::move(*__orig));
918 template<
typename _Tp,
typename =
void>
919 struct __is_bitwise_relocatable
920 : is_trivial<_Tp> { };
922 template <
typename _Tp,
typename _Up>
923 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
924 __relocate_a_1(_Tp* __first, _Tp* __last,
925 _Tp* __result, allocator<_Up>&) noexcept
927 ptrdiff_t __count = __last - __first;
929 __builtin_memmove(__result, __first, __count *
sizeof(_Tp));
930 return __result + __count;
933 template <
typename _InputIterator,
typename _ForwardIterator,
935 inline _ForwardIterator
936 __relocate_a_1(_InputIterator __first, _InputIterator __last,
937 _ForwardIterator __result, _Allocator& __alloc)
938 noexcept(noexcept(std::__relocate_object_a(
std::addressof(*__result),
942 typedef typename iterator_traits<_InputIterator>::value_type
944 typedef typename iterator_traits<_ForwardIterator>::value_type
947 "relocation is only possible for values of the same type");
948 _ForwardIterator __cur = __result;
949 for (; __first != __last; ++__first, (void)++__cur)
955 template <
typename _InputIterator,
typename _ForwardIterator,
957 inline _ForwardIterator
958 __relocate_a(_InputIterator __first, _InputIterator __last,
959 _ForwardIterator __result, _Allocator& __alloc)
960 noexcept(noexcept(__relocate_a_1(std::__niter_base(__first),
961 std::__niter_base(__last),
962 std::__niter_base(__result), __alloc)))
964 return __relocate_a_1(std::__niter_base(__first),
965 std::__niter_base(__last),
966 std::__niter_base(__result), __alloc);
970 _GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
void uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__x)
Copies the value x into the range [first,last).
_ForwardIterator uninitialized_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result)
Copies 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).
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
Uniform interface to all allocator types.
_ForwardIterator uninitialized_copy_n(_InputIterator __first, _Size __n, _ForwardIterator __result)
Copies the range [first,first+n) into result.
Uniform interface to C++98 and C++11 allocators.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
void _Construct(_T1 *__p, _Args &&... __args)
void _Destroy(_Tp *__pointer)
_GLIBCXX17_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...