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;
126 typedef typename iterator_traits<_InputIterator>::reference _RefType1;
127 typedef typename iterator_traits<_ForwardIterator>::reference _RefType2;
128 const bool __assignable = is_assignable<_RefType2, _RefType1>::value;
131 return std::__uninitialized_copy<__is_trivial(_ValueType1)
132 && __is_trivial(_ValueType2)
134 __uninit_copy(__first, __last, __result);
138 template<
bool _TrivialValueType>
139 struct __uninitialized_fill
141 template<
typename _ForwardIterator,
typename _Tp>
143 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
146 _ForwardIterator __cur = __first;
149 for (; __cur != __last; ++__cur)
155 __throw_exception_again;
161 struct __uninitialized_fill<true>
163 template<
typename _ForwardIterator,
typename _Tp>
165 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
167 { std::fill(__first, __last, __x); }
179 template<
typename _ForwardIterator,
typename _Tp>
184 typedef typename iterator_traits<_ForwardIterator>::value_type
186 #if __cplusplus < 201103L 187 const bool __assignable =
true;
190 const bool __assignable = is_copy_assignable<_ValueType>::value;
193 std::__uninitialized_fill<__is_trivial(_ValueType) && __assignable>::
194 __uninit_fill(__first, __last, __x);
198 template<
bool _TrivialValueType>
199 struct __uninitialized_fill_n
201 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
202 static _ForwardIterator
203 __uninit_fill_n(_ForwardIterator __first, _Size __n,
206 _ForwardIterator __cur = __first;
209 for (; __n > 0; --__n, ++__cur)
216 __throw_exception_again;
222 struct __uninitialized_fill_n<true>
224 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
225 static _ForwardIterator
226 __uninit_fill_n(_ForwardIterator __first, _Size __n,
242 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
243 inline _ForwardIterator
246 typedef typename iterator_traits<_ForwardIterator>::value_type
248 #if __cplusplus < 201103L 249 const bool __assignable =
true;
252 const bool __assignable = is_copy_assignable<_ValueType>::value;
254 return __uninitialized_fill_n<__is_trivial(_ValueType) && __assignable>::
255 __uninit_fill_n(__first, __n, __x);
264 template<
typename _InputIterator,
typename _ForwardIterator,
267 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
268 _ForwardIterator __result, _Allocator& __alloc)
270 _ForwardIterator __cur = __result;
274 for (; __first != __last; ++__first, (void)++__cur)
281 __throw_exception_again;
285 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp>
286 inline _ForwardIterator
287 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
291 template<
typename _InputIterator,
typename _ForwardIterator,
293 inline _ForwardIterator
294 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
295 _ForwardIterator __result, _Allocator& __alloc)
297 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
298 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
302 template<
typename _InputIterator,
typename _ForwardIterator,
304 inline _ForwardIterator
305 __uninitialized_move_if_noexcept_a(_InputIterator __first,
306 _InputIterator __last,
307 _ForwardIterator __result,
310 return std::__uninitialized_copy_a
311 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
312 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
315 template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
317 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
318 const _Tp& __x, _Allocator& __alloc)
320 _ForwardIterator __cur = __first;
324 for (; __cur != __last; ++__cur)
330 __throw_exception_again;
334 template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
336 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
340 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
343 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
344 const _Tp& __x, _Allocator& __alloc)
346 _ForwardIterator __cur = __first;
350 for (; __n > 0; --__n, ++__cur)
357 __throw_exception_again;
361 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
363 inline _ForwardIterator
364 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
378 template<
typename _InputIterator1,
typename _InputIterator2,
379 typename _ForwardIterator,
typename _Allocator>
380 inline _ForwardIterator
381 __uninitialized_copy_move(_InputIterator1 __first1,
382 _InputIterator1 __last1,
383 _InputIterator2 __first2,
384 _InputIterator2 __last2,
385 _ForwardIterator __result,
388 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
393 return std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
398 __throw_exception_again;
406 template<
typename _InputIterator1,
typename _InputIterator2,
407 typename _ForwardIterator,
typename _Allocator>
408 inline _ForwardIterator
409 __uninitialized_move_copy(_InputIterator1 __first1,
410 _InputIterator1 __last1,
411 _InputIterator2 __first2,
412 _InputIterator2 __last2,
413 _ForwardIterator __result,
416 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
421 return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
426 __throw_exception_again;
433 template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
435 inline _ForwardIterator
436 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
437 const _Tp& __x, _InputIterator __first,
438 _InputIterator __last, _Allocator& __alloc)
440 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
443 return std::__uninitialized_move_a(__first, __last, __mid, __alloc);
448 __throw_exception_again;
455 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
458 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
459 _ForwardIterator __first2,
460 _ForwardIterator __last2,
const _Tp& __x,
463 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
468 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
473 __throw_exception_again;
477 #if __cplusplus >= 201103L 481 template<
bool _TrivialValueType>
482 struct __uninitialized_default_1
484 template<
typename _ForwardIterator>
486 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
488 _ForwardIterator __cur = __first;
491 for (; __cur != __last; ++__cur)
497 __throw_exception_again;
503 struct __uninitialized_default_1<true>
505 template<
typename _ForwardIterator>
507 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
509 typedef typename iterator_traits<_ForwardIterator>::value_type
512 std::fill(__first, __last, _ValueType());
516 template<
bool _TrivialValueType>
517 struct __uninitialized_default_n_1
519 template<
typename _ForwardIterator,
typename _Size>
520 static _ForwardIterator
521 __uninit_default_n(_ForwardIterator __first, _Size __n)
523 _ForwardIterator __cur = __first;
526 for (; __n > 0; --__n, ++__cur)
533 __throw_exception_again;
539 struct __uninitialized_default_n_1<true>
541 template<
typename _ForwardIterator,
typename _Size>
542 static _ForwardIterator
543 __uninit_default_n(_ForwardIterator __first, _Size __n)
545 typedef typename iterator_traits<_ForwardIterator>::value_type
555 template<
typename _ForwardIterator>
557 __uninitialized_default(_ForwardIterator __first,
558 _ForwardIterator __last)
560 typedef typename iterator_traits<_ForwardIterator>::value_type
563 const bool __assignable = is_copy_assignable<_ValueType>::value;
565 std::__uninitialized_default_1<__is_trivial(_ValueType)
567 __uninit_default(__first, __last);
572 template<
typename _ForwardIterator,
typename _Size>
573 inline _ForwardIterator
574 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
576 typedef typename iterator_traits<_ForwardIterator>::value_type
579 const bool __assignable = is_copy_assignable<_ValueType>::value;
581 return __uninitialized_default_n_1<__is_trivial(_ValueType)
583 __uninit_default_n(__first, __n);
590 template<
typename _ForwardIterator,
typename _Allocator>
592 __uninitialized_default_a(_ForwardIterator __first,
593 _ForwardIterator __last,
596 _ForwardIterator __cur = __first;
600 for (; __cur != __last; ++__cur)
606 __throw_exception_again;
610 template<
typename _ForwardIterator,
typename _Tp>
612 __uninitialized_default_a(_ForwardIterator __first,
613 _ForwardIterator __last,
615 { std::__uninitialized_default(__first, __last); }
621 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
623 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
626 _ForwardIterator __cur = __first;
630 for (; __n > 0; --__n, ++__cur)
637 __throw_exception_again;
641 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
642 inline _ForwardIterator
643 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
645 {
return std::__uninitialized_default_n(__first, __n); }
647 template<
bool _TrivialValueType>
648 struct __uninitialized_default_novalue_1
650 template<
typename _ForwardIterator>
652 __uninit_default_novalue(_ForwardIterator __first,
653 _ForwardIterator __last)
655 _ForwardIterator __cur = __first;
658 for (; __cur != __last; ++__cur)
664 __throw_exception_again;
670 struct __uninitialized_default_novalue_1<true>
672 template<
typename _ForwardIterator>
674 __uninit_default_novalue(_ForwardIterator __first,
675 _ForwardIterator __last)
680 template<
bool _TrivialValueType>
681 struct __uninitialized_default_novalue_n_1
683 template<
typename _ForwardIterator,
typename _Size>
684 static _ForwardIterator
685 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
687 _ForwardIterator __cur = __first;
690 for (; __n > 0; --__n, ++__cur)
697 __throw_exception_again;
703 struct __uninitialized_default_novalue_n_1<true>
705 template<
typename _ForwardIterator,
typename _Size>
706 static _ForwardIterator
707 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
708 {
return std::next(__first, __n); }
714 template<
typename _ForwardIterator>
716 __uninitialized_default_novalue(_ForwardIterator __first,
717 _ForwardIterator __last)
719 typedef typename iterator_traits<_ForwardIterator>::value_type
722 std::__uninitialized_default_novalue_1<
723 is_trivially_default_constructible<_ValueType>::value>::
724 __uninit_default_novalue(__first, __last);
729 template<
typename _ForwardIterator,
typename _Size>
730 inline _ForwardIterator
731 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
733 typedef typename iterator_traits<_ForwardIterator>::value_type
736 return __uninitialized_default_novalue_n_1<
737 is_trivially_default_constructible<_ValueType>::value>::
738 __uninit_default_novalue_n(__first, __n);
741 template<
typename _InputIterator,
typename _Size,
742 typename _ForwardIterator>
744 __uninitialized_copy_n(_InputIterator __first, _Size __n,
747 _ForwardIterator __cur = __result;
750 for (; __n > 0; --__n, ++__first, ++__cur)
757 __throw_exception_again;
761 template<
typename _RandomAccessIterator,
typename _Size,
762 typename _ForwardIterator>
763 inline _ForwardIterator
764 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
765 _ForwardIterator __result,
769 template<
typename _InputIterator,
typename _Size,
770 typename _ForwardIterator>
772 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
775 _ForwardIterator __cur = __result;
778 for (; __n > 0; --__n, ++__first, ++__cur)
780 return {__first, __cur};
785 __throw_exception_again;
789 template<
typename _RandomAccessIterator,
typename _Size,
790 typename _ForwardIterator>
792 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
793 _ForwardIterator __result,
797 auto __first_res = std::next(__first, __n);
798 return {__first_res, __second_res};
810 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
811 inline _ForwardIterator
813 _ForwardIterator __result)
814 {
return std::__uninitialized_copy_n(__first, __n, __result,
817 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
819 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
820 _ForwardIterator __result)
823 std::__uninitialized_copy_n_pair(__first, __n, __result,
829 #if __cplusplus > 201402L 830 template <
typename _ForwardIterator>
832 uninitialized_default_construct(_ForwardIterator __first,
833 _ForwardIterator __last)
835 __uninitialized_default_novalue(__first, __last);
838 template <
typename _ForwardIterator,
typename _Size>
839 inline _ForwardIterator
840 uninitialized_default_construct_n(_ForwardIterator __first, _Size __count)
842 return __uninitialized_default_novalue_n(__first, __count);
845 template <
typename _ForwardIterator>
847 uninitialized_value_construct(_ForwardIterator __first,
848 _ForwardIterator __last)
850 return __uninitialized_default(__first, __last);
853 template <
typename _ForwardIterator,
typename _Size>
854 inline _ForwardIterator
855 uninitialized_value_construct_n(_ForwardIterator __first, _Size __count)
857 return __uninitialized_default_n(__first, __count);
860 template <
typename _InputIterator,
typename _ForwardIterator>
861 inline _ForwardIterator
862 uninitialized_move(_InputIterator __first, _InputIterator __last,
863 _ForwardIterator __result)
866 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
867 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
870 template <
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
872 uninitialized_move_n(_InputIterator __first, _Size __count,
873 _ForwardIterator __result)
875 auto __res = std::__uninitialized_copy_n_pair
876 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
878 return {__res.first.base(), __res.second};
881 template <
typename _Tp>
883 destroy_at(_Tp* __location)
888 template <
typename _ForwardIterator>
890 destroy(_ForwardIterator __first, _ForwardIterator __last)
895 template <
typename _ForwardIterator,
typename _Size>
896 inline _ForwardIterator
897 destroy_n(_ForwardIterator __first, _Size __count)
905 _GLIBCXX_END_NAMESPACE_VERSION
The standard allocator, as per [20.4].
_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.
_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.
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).
ISO C++ entities toplevel namespace is std.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
_ForwardIterator _Destroy_n(_ForwardIterator __first, _Size __count)
Struct holding two objects of arbitrary type.
void _Construct(_T1 *__p, _Args &&...__args)
Random-access iterators support a superset of bidirectional iterator operations.
_ForwardIterator uninitialized_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result)
Copies the range [first,last) into result.
void _Destroy(_Tp *__pointer)