58 #ifndef _STL_UNINITIALIZED_H
59 #define _STL_UNINITIALIZED_H 1
61 namespace std _GLIBCXX_VISIBILITY(default)
63 _GLIBCXX_BEGIN_NAMESPACE_VERSION
65 template<
bool _TrivialValueTypes>
66 struct __uninitialized_copy
68 template<
typename _InputIterator,
typename _ForwardIterator>
69 static _ForwardIterator
70 __uninit_copy(_InputIterator __first, _InputIterator __last,
71 _ForwardIterator __result)
73 _ForwardIterator __cur = __result;
76 for (; __first != __last; ++__first, ++__cur)
83 __throw_exception_again;
89 struct __uninitialized_copy<true>
91 template<
typename _InputIterator,
typename _ForwardIterator>
92 static _ForwardIterator
93 __uninit_copy(_InputIterator __first, _InputIterator __last,
94 _ForwardIterator __result)
95 {
return std::copy(__first, __last, __result); }
107 template<
typename _InputIterator,
typename _ForwardIterator>
108 inline _ForwardIterator
110 _ForwardIterator __result)
112 typedef typename iterator_traits<_InputIterator>::value_type
114 typedef typename iterator_traits<_ForwardIterator>::value_type
117 return std::__uninitialized_copy<(__is_trivial(_ValueType1)
118 && __is_trivial(_ValueType2))>::
119 __uninit_copy(__first, __last, __result);
123 template<
bool _TrivialValueType>
124 struct __uninitialized_fill
126 template<
typename _ForwardIterator,
typename _Tp>
128 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
131 _ForwardIterator __cur = __first;
134 for (; __cur != __last; ++__cur)
140 __throw_exception_again;
146 struct __uninitialized_fill<true>
148 template<
typename _ForwardIterator,
typename _Tp>
150 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
152 { std::fill(__first, __last, __x); }
164 template<
typename _ForwardIterator,
typename _Tp>
169 typedef typename iterator_traits<_ForwardIterator>::value_type
172 std::__uninitialized_fill<__is_trivial(_ValueType)>::
173 __uninit_fill(__first, __last, __x);
177 template<
bool _TrivialValueType>
178 struct __uninitialized_fill_n
180 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
182 __uninit_fill_n(_ForwardIterator __first, _Size __n,
185 _ForwardIterator __cur = __first;
188 for (; __n > 0; --__n, ++__cur)
194 __throw_exception_again;
200 struct __uninitialized_fill_n<true>
202 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
204 __uninit_fill_n(_ForwardIterator __first, _Size __n,
218 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
222 typedef typename iterator_traits<_ForwardIterator>::value_type
225 std::__uninitialized_fill_n<__is_trivial(_ValueType)>::
226 __uninit_fill_n(__first, __n, __x);
235 template<
typename _InputIterator,
typename _ForwardIterator,
238 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
239 _ForwardIterator __result, _Allocator& __alloc)
241 _ForwardIterator __cur = __result;
244 for (; __first != __last; ++__first, ++__cur)
245 __alloc.construct(std::__addressof(*__cur), *__first);
251 __throw_exception_again;
255 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp>
256 inline _ForwardIterator
257 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
258 _ForwardIterator __result, allocator<_Tp>&)
261 template<
typename _InputIterator,
typename _ForwardIterator,
263 inline _ForwardIterator
264 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
265 _ForwardIterator __result, _Allocator& __alloc)
267 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
268 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
272 template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
274 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
275 const _Tp& __x, _Allocator& __alloc)
277 _ForwardIterator __cur = __first;
280 for (; __cur != __last; ++__cur)
281 __alloc.construct(std::__addressof(*__cur), __x);
286 __throw_exception_again;
290 template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
292 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
293 const _Tp& __x, allocator<_Tp2>&)
296 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
299 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
300 const _Tp& __x, _Allocator& __alloc)
302 _ForwardIterator __cur = __first;
305 for (; __n > 0; --__n, ++__cur)
306 __alloc.construct(std::__addressof(*__cur), __x);
311 __throw_exception_again;
315 template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
318 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
319 const _Tp& __x, allocator<_Tp2>&)
332 template<
typename _InputIterator1,
typename _InputIterator2,
333 typename _ForwardIterator,
typename _Allocator>
334 inline _ForwardIterator
335 __uninitialized_copy_move(_InputIterator1 __first1,
336 _InputIterator1 __last1,
337 _InputIterator2 __first2,
338 _InputIterator2 __last2,
339 _ForwardIterator __result,
342 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
347 return std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
352 __throw_exception_again;
360 template<
typename _InputIterator1,
typename _InputIterator2,
361 typename _ForwardIterator,
typename _Allocator>
362 inline _ForwardIterator
363 __uninitialized_move_copy(_InputIterator1 __first1,
364 _InputIterator1 __last1,
365 _InputIterator2 __first2,
366 _InputIterator2 __last2,
367 _ForwardIterator __result,
370 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
375 return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
380 __throw_exception_again;
387 template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
389 inline _ForwardIterator
390 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
391 const _Tp& __x, _InputIterator __first,
392 _InputIterator __last, _Allocator& __alloc)
394 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
397 return std::__uninitialized_move_a(__first, __last, __mid, __alloc);
402 __throw_exception_again;
409 template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
412 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
413 _ForwardIterator __first2,
414 _ForwardIterator __last2,
const _Tp& __x,
417 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
422 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
427 __throw_exception_again;
431 #ifdef __GXX_EXPERIMENTAL_CXX0X__
435 template<
bool _TrivialValueType>
436 struct __uninitialized_default_1
438 template<
typename _ForwardIterator>
440 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
442 _ForwardIterator __cur = __first;
445 for (; __cur != __last; ++__cur)
451 __throw_exception_again;
457 struct __uninitialized_default_1<true>
459 template<
typename _ForwardIterator>
461 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
463 typedef typename iterator_traits<_ForwardIterator>::value_type
466 std::fill(__first, __last, _ValueType());
470 template<
bool _TrivialValueType>
471 struct __uninitialized_default_n_1
473 template<
typename _ForwardIterator,
typename _Size>
475 __uninit_default_n(_ForwardIterator __first, _Size __n)
477 _ForwardIterator __cur = __first;
480 for (; __n > 0; --__n, ++__cur)
486 __throw_exception_again;
492 struct __uninitialized_default_n_1<true>
494 template<
typename _ForwardIterator,
typename _Size>
496 __uninit_default_n(_ForwardIterator __first, _Size __n)
498 typedef typename iterator_traits<_ForwardIterator>::value_type
508 template<
typename _ForwardIterator>
510 __uninitialized_default(_ForwardIterator __first,
511 _ForwardIterator __last)
513 typedef typename iterator_traits<_ForwardIterator>::value_type
516 std::__uninitialized_default_1<__is_trivial(_ValueType)>::
517 __uninit_default(__first, __last);
522 template<
typename _ForwardIterator,
typename _Size>
524 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
526 typedef typename iterator_traits<_ForwardIterator>::value_type
529 std::__uninitialized_default_n_1<__is_trivial(_ValueType)>::
530 __uninit_default_n(__first, __n);
533 template<
typename _Tp,
typename _Allocator>
535 _Construct_default_a_impl(_Tp* __ptr, _Allocator& __alloc,
void*)
536 -> decltype(__alloc.construct(__ptr))
537 {
return __alloc.construct(__ptr); }
539 template<
typename _Tp,
typename _Allocator>
541 _Construct_default_a_impl(_Tp* __ptr, _Allocator& __alloc, ...)
544 template<
typename _Tp,
typename _Allocator>
546 _Construct_default_a(_Tp* __ptr, _Allocator& __alloc)
547 { _Construct_default_a_impl(__ptr, __alloc,
nullptr); }
552 template<
typename _ForwardIterator,
typename _Allocator>
554 __uninitialized_default_a(_ForwardIterator __first,
555 _ForwardIterator __last,
558 _ForwardIterator __cur = __first;
561 for (; __cur != __last; ++__cur)
562 _Construct_default_a(std::__addressof(*__cur), __alloc);
567 __throw_exception_again;
571 template<
typename _ForwardIterator,
typename _Tp>
573 __uninitialized_default_a(_ForwardIterator __first,
574 _ForwardIterator __last,
576 { std::__uninitialized_default(__first, __last); }
582 template<
typename _ForwardIterator,
typename _Size,
typename _Allocator>
584 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
587 _ForwardIterator __cur = __first;
590 for (; __n > 0; --__n, ++__cur)
591 _Construct_default_a(std::__addressof(*__cur), __alloc);
596 __throw_exception_again;
600 template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
602 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
604 { std::__uninitialized_default_n(__first, __n); }
607 template<
typename _InputIterator,
typename _Size,
608 typename _ForwardIterator>
610 __uninitialized_copy_n(_InputIterator __first, _Size __n,
611 _ForwardIterator __result, input_iterator_tag)
613 _ForwardIterator __cur = __result;
616 for (; __n > 0; --__n, ++__first, ++__cur)
623 __throw_exception_again;
627 template<
typename _RandomAccessIterator,
typename _Size,
628 typename _ForwardIterator>
629 inline _ForwardIterator
630 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
631 _ForwardIterator __result,
632 random_access_iterator_tag)
644 template<
typename _InputIterator,
typename _Size,
typename _ForwardIterator>
645 inline _ForwardIterator
647 _ForwardIterator __result)
648 {
return std::__uninitialized_copy_n(__first, __n, __result,
652 _GLIBCXX_END_NAMESPACE_VERSION