libstdc++
stl_uninitialized.h
Go to the documentation of this file.
1// Raw memory manipulators -*- C++ -*-
2
3// Copyright (C) 2001-2025 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/*
26 *
27 * Copyright (c) 1994
28 * Hewlett-Packard Company
29 *
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
37 *
38 *
39 * Copyright (c) 1996,1997
40 * Silicon Graphics Computer Systems, Inc.
41 *
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
49 */
50
51/** @file bits/stl_uninitialized.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{memory}
54 */
55
56#ifndef _STL_UNINITIALIZED_H
57#define _STL_UNINITIALIZED_H 1
58
59#if __cplusplus >= 201103L
60# include <type_traits>
61# include <bits/ptr_traits.h> // to_address
62# include <bits/stl_pair.h> // pair
63# include <bits/stl_algobase.h> // fill, fill_n
64#endif
65
66#include <bits/cpp_type_traits.h> // __is_pointer
67#include <bits/stl_iterator_base_funcs.h> // distance, advance
68#include <bits/stl_iterator.h> // __niter_base
69#include <ext/alloc_traits.h> // __alloc_traits
70
71namespace std _GLIBCXX_VISIBILITY(default)
72{
73_GLIBCXX_BEGIN_NAMESPACE_VERSION
74
75 /** @addtogroup memory
76 * @{
77 */
78
79 /// @cond undocumented
80
81 template<typename _ForwardIterator, typename _Alloc = void>
82 struct _UninitDestroyGuard
83 {
84 _GLIBCXX20_CONSTEXPR
85 explicit
86 _UninitDestroyGuard(_ForwardIterator& __first, _Alloc& __a)
87 : _M_first(__first), _M_cur(__builtin_addressof(__first)), _M_alloc(__a)
88 { }
89
90 _GLIBCXX20_CONSTEXPR
91 ~_UninitDestroyGuard()
92 {
93 if (__builtin_expect(_M_cur != 0, 0))
94 std::_Destroy(_M_first, *_M_cur, _M_alloc);
95 }
96
97 _GLIBCXX20_CONSTEXPR
98 void release() { _M_cur = 0; }
99
100 private:
101 _ForwardIterator const _M_first;
102 _ForwardIterator* _M_cur;
103 _Alloc& _M_alloc;
104
105 _UninitDestroyGuard(const _UninitDestroyGuard&);
106 };
107
108 template<typename _ForwardIterator>
109 struct _UninitDestroyGuard<_ForwardIterator, void>
110 {
111 _GLIBCXX20_CONSTEXPR
112 explicit
113 _UninitDestroyGuard(_ForwardIterator& __first)
114 : _M_first(__first), _M_cur(__builtin_addressof(__first))
115 { }
116
117 _GLIBCXX20_CONSTEXPR
118 ~_UninitDestroyGuard()
119 {
120 if (__builtin_expect(_M_cur != 0, 0))
121 std::_Destroy(_M_first, *_M_cur);
122 }
123
124 _GLIBCXX20_CONSTEXPR
125 void release() { _M_cur = 0; }
126
127 _ForwardIterator const _M_first;
128 _ForwardIterator* _M_cur;
129
130 private:
131 _UninitDestroyGuard(const _UninitDestroyGuard&);
132 };
133
134 // This is the default implementation of std::uninitialized_copy.
135 // This can be used with C++20 iterators and non-common ranges.
136 template<typename _InputIterator, typename _Sentinel,
137 typename _ForwardIterator>
138 _GLIBCXX20_CONSTEXPR
139 _ForwardIterator
140 __do_uninit_copy(_InputIterator __first, _Sentinel __last,
141 _ForwardIterator __result)
142 {
143 _UninitDestroyGuard<_ForwardIterator> __guard(__result);
144 for (; __first != __last; ++__first, (void)++__result)
145 std::_Construct(std::__addressof(*__result), *__first);
146 __guard.release();
147 return __result;
148 }
149
150#if __cplusplus < 201103L
151
152 // True if we can unwrap _Iter to get a pointer by using std::__niter_base.
153 template<typename _Iter,
154 typename _Base = __decltype(std::__niter_base(*(_Iter*)0))>
155 struct __unwrappable_niter
156 { enum { __value = false }; };
157
158 template<typename _Iter, typename _Tp>
159 struct __unwrappable_niter<_Iter, _Tp*>
160 { enum { __value = true }; };
161
162 // Use template specialization for C++98 when 'if constexpr' can't be used.
163 template<bool _CanMemcpy>
164 struct __uninitialized_copy
165 {
166 template<typename _InputIterator, typename _ForwardIterator>
167 static _ForwardIterator
168 __uninit_copy(_InputIterator __first, _InputIterator __last,
169 _ForwardIterator __result)
170 { return std::__do_uninit_copy(__first, __last, __result); }
171 };
172
173 template<>
174 struct __uninitialized_copy<true>
175 {
176 // Overload for generic iterators.
177 template<typename _InputIterator, typename _ForwardIterator>
178 static _ForwardIterator
179 __uninit_copy(_InputIterator __first, _InputIterator __last,
180 _ForwardIterator __result)
181 {
182 if (__unwrappable_niter<_InputIterator>::__value
183 && __unwrappable_niter<_ForwardIterator>::__value)
184 {
185 __uninit_copy(std::__niter_base(__first),
186 std::__niter_base(__last),
187 std::__niter_base(__result));
188 std::advance(__result, std::distance(__first, __last));
189 return __result;
190 }
191 else
192 return std::__do_uninit_copy(__first, __last, __result);
193 }
194
195 // Overload for pointers.
196 template<typename _Tp, typename _Up>
197 static _Up*
198 __uninit_copy(_Tp* __first, _Tp* __last, _Up* __result)
199 {
200 // Ensure that we don't successfully memcpy in cases that should be
201 // ill-formed because is_constructible<_Up, _Tp&> is false.
202 typedef __typeof__(static_cast<_Up>(*__first)) __check
203 __attribute__((__unused__));
204
205 const ptrdiff_t __n = __last - __first;
206 if (__builtin_expect(__n > 0, true))
207 {
208 __builtin_memcpy(__result, __first, __n * sizeof(_Tp));
209 __result += __n;
210 }
211 return __result;
212 }
213 };
214#endif
215 /// @endcond
216
217#pragma GCC diagnostic push
218#pragma GCC diagnostic ignored "-Wc++17-extensions"
219 /**
220 * @brief Copies the range [first,last) into result.
221 * @param __first An input iterator.
222 * @param __last An input iterator.
223 * @param __result A forward iterator.
224 * @return __result + (__last - __first)
225 *
226 * Like std::copy, but does not require an initialized output range.
227 */
228 template<typename _InputIterator, typename _ForwardIterator>
229 inline _ForwardIterator
230 uninitialized_copy(_InputIterator __first, _InputIterator __last,
231 _ForwardIterator __result)
232 {
233 // We can use memcpy to copy the ranges under these conditions:
234 //
235 // _ForwardIterator and _InputIterator are both contiguous iterators,
236 // so that we can turn them into pointers to pass to memcpy.
237 // Before C++20 we can't detect all contiguous iterators, so we only
238 // handle built-in pointers and __normal_iterator<T*, C> types.
239 //
240 // The value types of both iterators are trivially-copyable types,
241 // so that memcpy is not undefined and can begin the lifetime of
242 // new objects in the output range.
243 //
244 // Finally, memcpy from the source type, S, to the destination type, D,
245 // must give the same value as initialization of D from S would give.
246 // We require is_trivially_constructible<D, S> to be true, but that is
247 // not sufficient. Some cases of trivial initialization are not just a
248 // bitwise copy, even when sizeof(D) == sizeof(S),
249 // e.g. bit_cast<unsigned>(1.0f) != 1u because the corresponding bits
250 // of the value representations do not have the same meaning.
251 // We cannot tell when this condition is true in general,
252 // so we rely on the __memcpyable trait.
253
254#if __cplusplus >= 201103L
255 using _Dest = decltype(std::__niter_base(__result));
256 using _Src = decltype(std::__niter_base(__first));
258
259 if constexpr (!__is_trivially_constructible(_ValT, decltype(*__first)))
260 return std::__do_uninit_copy(__first, __last, __result);
261 else if constexpr (__memcpyable<_Dest, _Src>::__value)
262 {
263 ptrdiff_t __n = __last - __first;
264 if (__n > 0) [[__likely__]]
265 {
266 using _ValT = typename remove_pointer<_Src>::type;
267 __builtin_memcpy(std::__niter_base(__result),
268 std::__niter_base(__first),
269 __n * sizeof(_ValT));
270 __result += __n;
271 }
272 return __result;
273 }
274#if __cpp_lib_concepts
275 else if constexpr (contiguous_iterator<_ForwardIterator>
276 && contiguous_iterator<_InputIterator>)
277 {
278 using _DestPtr = decltype(std::to_address(__result));
279 using _SrcPtr = decltype(std::to_address(__first));
280 if constexpr (__memcpyable<_DestPtr, _SrcPtr>::__value)
281 {
282 if (auto __n = __last - __first; __n > 0) [[likely]]
283 {
284 void* __dest = std::to_address(__result);
285 const void* __src = std::to_address(__first);
286 size_t __nbytes = __n * sizeof(remove_pointer_t<_DestPtr>);
287 __builtin_memcpy(__dest, __src, __nbytes);
288 __result += __n;
289 }
290 return __result;
291 }
292 else
293 return std::__do_uninit_copy(__first, __last, __result);
294 }
295#endif
296 else
297 return std::__do_uninit_copy(__first, __last, __result);
298#else // C++98
300 _ValueType1;
302 _ValueType2;
303
304 const bool __can_memcpy
305 = __memcpyable<_ValueType1*, _ValueType2*>::__value
306 && __is_trivially_constructible(_ValueType2, __decltype(*__first));
307
308 return __uninitialized_copy<__can_memcpy>::
309 __uninit_copy(__first, __last, __result);
310#endif
311 }
312#pragma GCC diagnostic pop
313
314 /// @cond undocumented
315
316 // This is the default implementation of std::uninitialized_fill.
317 template<typename _ForwardIterator, typename _Tp>
318 _GLIBCXX20_CONSTEXPR void
319 __do_uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
320 const _Tp& __x)
321 {
322 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
323 for (; __first != __last; ++__first)
324 std::_Construct(std::__addressof(*__first), __x);
325 __guard.release();
326 }
327
328#if __cplusplus < 201103L
329 // Use template specialization for C++98 when 'if constexpr' can't be used.
330 template<bool _CanMemset>
331 struct __uninitialized_fill
332 {
333 template<typename _ForwardIterator, typename _Tp>
334 static void
335 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
336 const _Tp& __x)
337 { std::__do_uninit_fill(__first, __last, __x); }
338 };
339
340 template<>
341 struct __uninitialized_fill<true>
342 {
343 // Overload for generic iterators.
344 template<typename _ForwardIterator, typename _Tp>
345 static void
346 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
347 const _Tp& __x)
348 {
349 if (__unwrappable_niter<_ForwardIterator>::__value)
350 __uninit_fill(std::__niter_base(__first),
351 std::__niter_base(__last),
352 __x);
353 else
354 std::__do_uninit_copy(__first, __last, __x);
355 }
356
357 // Overload for pointers.
358 template<typename _Up, typename _Tp>
359 static void
360 __uninit_fill(_Up* __first, _Up* __last, const _Tp& __x)
361 {
362 // Ensure that we don't successfully memset in cases that should be
363 // ill-formed because is_constructible<_Up, const _Tp&> is false.
364 typedef __typeof__(static_cast<_Up>(__x)) __check
365 __attribute__((__unused__));
366
367 if (__first != __last)
368 __builtin_memset(__first, (unsigned char)__x, __last - __first);
369 }
370 };
371#endif
372 /// @endcond
373
374 /**
375 * @brief Copies the value x into the range [first,last).
376 * @param __first A forward iterator.
377 * @param __last A forward iterator.
378 * @param __x The source value.
379 * @return Nothing.
380 *
381 * Like std::fill, but does not require an initialized output range.
382 */
383 template<typename _ForwardIterator, typename _Tp>
384 inline void
385 uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last,
386 const _Tp& __x)
387 {
388 // We would like to use memset to optimize this loop when possible.
389 // As for std::uninitialized_copy, the optimization requires
390 // contiguous iterators and trivially copyable value types,
391 // with the additional requirement that sizeof(_Tp) == 1 because
392 // memset only writes single bytes.
393
394 // FIXME: We could additionally enable this for 1-byte enums.
395 // Maybe any 1-byte Val if is_trivially_constructible<Val, const T&>?
396
398 _ValueType;
399
400#if __cplusplus >= 201103L
401#pragma GCC diagnostic push
402#pragma GCC diagnostic ignored "-Wc++17-extensions"
403 if constexpr (__is_byte<_ValueType>::__value)
406 {
407 using _BasePtr = decltype(std::__niter_base(__first));
408 if constexpr (is_pointer<_BasePtr>::value)
409 {
410 void* __dest = std::__niter_base(__first);
411 ptrdiff_t __n = __last - __first;
412 if (__n > 0) [[__likely__]]
413 __builtin_memset(__dest, (unsigned char)__x, __n);
414 return;
415 }
416#if __cpp_lib_concepts
417 else if constexpr (contiguous_iterator<_ForwardIterator>)
418 {
419 auto __dest = std::to_address(__first);
420 auto __n = __last - __first;
421 if (__n > 0) [[__likely__]]
422 __builtin_memset(__dest, (unsigned char)__x, __n);
423 return;
424 }
425#endif
426 }
427 std::__do_uninit_fill(__first, __last, __x);
428#pragma GCC diagnostic pop
429#else // C++98
430 const bool __can_memset = __is_byte<_ValueType>::__value
431 && __is_integer<_Tp>::__value;
432
433 __uninitialized_fill<__can_memset>::__uninit_fill(__first, __last, __x);
434#endif
435 }
436
437 /// @cond undocumented
438
439 // This is the default implementation of std::uninitialized_fill_n.
440 template<typename _ForwardIterator, typename _Size, typename _Tp>
441 _GLIBCXX20_CONSTEXPR
442 _ForwardIterator
443 __do_uninit_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
444 {
445 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
446#if __cplusplus >= 201103L
447#pragma GCC diagnostic push
448#pragma GCC diagnostic ignored "-Wc++17-extensions"
449 if constexpr (is_integral<_Size>::value)
450 // Loop will never terminate if __n is negative.
451 __glibcxx_assert(__n >= 0);
452 else if constexpr (is_floating_point<_Size>::value)
453 // Loop will never terminate if __n is not an integer.
454 __glibcxx_assert(__n >= 0 && static_cast<size_t>(__n) == __n);
455#pragma GCC diagnostic pop
456#endif
457 for (; __n--; ++__first)
458 std::_Construct(std::__addressof(*__first), __x);
459 __guard.release();
460 return __first;
461 }
462
463#if __cplusplus < 201103L
464 // Use template specialization for C++98 when 'if constexpr' can't be used.
465 template<bool _CanMemset>
466 struct __uninitialized_fill_n
467 {
468 template<typename _ForwardIterator, typename _Size, typename _Tp>
469 static _ForwardIterator
470 __uninit_fill_n(_ForwardIterator __first, _Size __n,
471 const _Tp& __x)
472 { return std::__do_uninit_fill_n(__first, __n, __x); }
473 };
474
475 template<>
476 struct __uninitialized_fill_n<true>
477 {
478 // Overload for generic iterators.
479 template<typename _ForwardIterator, typename _Size, typename _Tp>
480 static _ForwardIterator
481 __uninit_fill_n(_ForwardIterator __first, _Size __n,
482 const _Tp& __x)
483 {
484 if (__unwrappable_niter<_ForwardIterator>::__value)
485 {
486 _ForwardIterator __last = __first;
487 std::advance(__last, __n);
488 __uninitialized_fill<true>::__uninit_fill(__first, __last, __x);
489 return __last;
490 }
491 else
492 return std::__do_uninit_fill_n(__first, __n, __x);
493 }
494 };
495#endif
496 /// @endcond
497
498#pragma GCC diagnostic push
499#pragma GCC diagnostic ignored "-Wc++17-extensions"
500 // _GLIBCXX_RESOLVE_LIB_DEFECTS
501 // DR 1339. uninitialized_fill_n should return the end of its range
502 /**
503 * @brief Copies the value x into the range [first,first+n).
504 * @param __first A forward iterator.
505 * @param __n The number of copies to make.
506 * @param __x The source value.
507 * @return __first + __n.
508 *
509 * Like std::fill_n, but does not require an initialized output range.
510 */
511 template<typename _ForwardIterator, typename _Size, typename _Tp>
512 inline _ForwardIterator
513 uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
514 {
515 // See uninitialized_fill conditions. We also require _Size to be
516 // an integer. The standard only requires _Size to be decrementable
517 // and contextually convertible to bool, so don't assume first+n works.
518
519 // FIXME: We could additionally enable this for 1-byte enums.
520
522 _ValueType;
523
524#if __cplusplus >= 201103L
525 if constexpr (__is_byte<_ValueType>::__value)
526 if constexpr (is_integral<_Tp>::value)
527 if constexpr (is_integral<_Size>::value)
528 {
529 using _BasePtr = decltype(std::__niter_base(__first));
530 if constexpr (is_pointer<_BasePtr>::value)
531 {
532 void* __dest = std::__niter_base(__first);
533 if (__n > 0) [[__likely__]]
534 {
535 __builtin_memset(__dest, (unsigned char)__x, __n);
536 __first += __n;
537 }
538 return __first;
539 }
540#if __cpp_lib_concepts
541 else if constexpr (contiguous_iterator<_ForwardIterator>)
542 {
543 auto __dest = std::to_address(__first);
544 if (__n > 0) [[__likely__]]
545 {
546 __builtin_memset(__dest, (unsigned char)__x, __n);
547 __first += __n;
548 }
549 return __first;
550 }
551#endif
552 }
553 return std::__do_uninit_fill_n(__first, __n, __x);
554#else // C++98
555 const bool __can_memset = __is_byte<_ValueType>::__value
556 && __is_integer<_Tp>::__value
557 && __is_integer<_Size>::__value;
558
559 return __uninitialized_fill_n<__can_memset>::
560 __uninit_fill_n(__first, __n, __x);
561#endif
562 }
563#pragma GCC diagnostic pop
564
565 /// @cond undocumented
566
567 // Extensions: versions of uninitialized_copy, uninitialized_fill,
568 // and uninitialized_fill_n that take an allocator parameter.
569 // We dispatch back to the standard versions when we're given the
570 // default allocator. For nondefault allocators we do not use
571 // any of the POD optimizations.
572
573 template<typename _InputIterator, typename _Sentinel,
574 typename _ForwardIterator, typename _Allocator>
575 _GLIBCXX20_CONSTEXPR
576 _ForwardIterator
577 __uninitialized_copy_a(_InputIterator __first, _Sentinel __last,
578 _ForwardIterator __result, _Allocator& __alloc)
579 {
580 _UninitDestroyGuard<_ForwardIterator, _Allocator>
581 __guard(__result, __alloc);
582
584 for (; __first != __last; ++__first, (void)++__result)
585 __traits::construct(__alloc, std::__addressof(*__result), *__first);
586 __guard.release();
587 return __result;
588 }
589
590#if _GLIBCXX_HOSTED
591 template<typename _InputIterator, typename _Sentinel,
592 typename _ForwardIterator, typename _Tp>
593 _GLIBCXX20_CONSTEXPR
594 inline _ForwardIterator
595 __uninitialized_copy_a(_InputIterator __first, _Sentinel __last,
596 _ForwardIterator __result, allocator<_Tp>&)
597 {
598#ifdef __cpp_lib_is_constant_evaluated
599 if (std::is_constant_evaluated())
600 return std::__do_uninit_copy(std::move(__first), __last, __result);
601#endif
602
603#ifdef __glibcxx_ranges
604 if constexpr (!is_same_v<_InputIterator, _Sentinel>)
605 {
606 // Convert to a common range if possible, to benefit from memcpy
607 // optimizations that std::uninitialized_copy might use.
608 if constexpr (sized_sentinel_for<_Sentinel, _InputIterator>
609 && random_access_iterator<_InputIterator>)
610 return std::uninitialized_copy(__first,
611 __first + (__last - __first),
612 __result);
613 else // Just use default implementation.
614 return std::__do_uninit_copy(std::move(__first), __last, __result);
615 }
616 else
617 return std::uninitialized_copy(std::move(__first), __last, __result);
618#else
619 return std::uninitialized_copy(__first, __last, __result);
620#endif
621 }
622#endif
623
624 template<typename _InputIterator, typename _ForwardIterator,
625 typename _Allocator>
626 _GLIBCXX20_CONSTEXPR
627 inline _ForwardIterator
628 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
629 _ForwardIterator __result, _Allocator& __alloc)
630 {
631 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
632 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
633 __result, __alloc);
634 }
635
636 template<typename _InputIterator, typename _ForwardIterator,
637 typename _Allocator>
638 _GLIBCXX20_CONSTEXPR
639 inline _ForwardIterator
640 __uninitialized_move_if_noexcept_a(_InputIterator __first,
641 _InputIterator __last,
642 _ForwardIterator __result,
643 _Allocator& __alloc)
644 {
645 return std::__uninitialized_copy_a
646 (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
647 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
648 }
649
650 template<typename _ForwardIterator, typename _Tp, typename _Allocator>
651 _GLIBCXX20_CONSTEXPR
652 void
653 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
654 const _Tp& __x, _Allocator& __alloc)
655 {
656 _UninitDestroyGuard<_ForwardIterator, _Allocator>
657 __guard(__first, __alloc);
658
659 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
660 for (; __first != __last; ++__first)
661 __traits::construct(__alloc, std::__addressof(*__first), __x);
662
663 __guard.release();
664 }
665
666#if _GLIBCXX_HOSTED
667 template<typename _ForwardIterator, typename _Tp, typename _Tp2>
668 _GLIBCXX20_CONSTEXPR
669 inline void
670 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
671 const _Tp& __x, allocator<_Tp2>&)
672 {
673#ifdef __cpp_lib_is_constant_evaluated
674 if (std::is_constant_evaluated())
675 return std::__do_uninit_fill(__first, __last, __x);
676#endif
677 std::uninitialized_fill(__first, __last, __x);
678 }
679#endif
680
681 template<typename _ForwardIterator, typename _Size, typename _Tp,
682 typename _Allocator>
683 _GLIBCXX20_CONSTEXPR
684 _ForwardIterator
685 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
686 const _Tp& __x, _Allocator& __alloc)
687 {
688 _UninitDestroyGuard<_ForwardIterator, _Allocator>
689 __guard(__first, __alloc);
690 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
691 for (; __n > 0; --__n, (void) ++__first)
692 __traits::construct(__alloc, std::__addressof(*__first), __x);
693 __guard.release();
694 return __first;
695 }
696
697#if _GLIBCXX_HOSTED
698 template<typename _ForwardIterator, typename _Size, typename _Tp,
699 typename _Tp2>
700 _GLIBCXX20_CONSTEXPR
701 inline _ForwardIterator
702 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
703 const _Tp& __x, allocator<_Tp2>&)
704 {
705#ifdef __cpp_lib_is_constant_evaluated
706 if (std::is_constant_evaluated())
707 return std::__do_uninit_fill_n(__first, __n, __x);
708#endif
709 return std::uninitialized_fill_n(__first, __n, __x);
710 }
711#endif
712
713 // Extensions: __uninitialized_copy_move, __uninitialized_move_copy,
714 // __uninitialized_fill_move, __uninitialized_move_fill.
715 // All of these algorithms take a user-supplied allocator, which is used
716 // for construction and destruction.
717
718 // __uninitialized_copy_move
719 // Copies [first1, last1) into [result, result + (last1 - first1)), and
720 // move [first2, last2) into
721 // [result, result + (last1 - first1) + (last2 - first2)).
722 template<typename _InputIterator1, typename _InputIterator2,
723 typename _ForwardIterator, typename _Allocator>
724 inline _ForwardIterator
725 __uninitialized_copy_move(_InputIterator1 __first1,
726 _InputIterator1 __last1,
727 _InputIterator2 __first2,
728 _InputIterator2 __last2,
729 _ForwardIterator __result,
730 _Allocator& __alloc)
731 {
732 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
733 __result, __alloc);
734 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__result,
735 __alloc);
736 __result = __mid; // Everything up to __mid is now guarded.
737 __result = std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
738 __guard.release();
739 return __result;
740 }
741
742 // __uninitialized_move_copy
743 // Moves [first1, last1) into [result, result + (last1 - first1)), and
744 // copies [first2, last2) into
745 // [result, result + (last1 - first1) + (last2 - first2)).
746 template<typename _InputIterator1, typename _InputIterator2,
747 typename _ForwardIterator, typename _Allocator>
748 inline _ForwardIterator
749 __uninitialized_move_copy(_InputIterator1 __first1,
750 _InputIterator1 __last1,
751 _InputIterator2 __first2,
752 _InputIterator2 __last2,
753 _ForwardIterator __result,
754 _Allocator& __alloc)
755 {
756 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
757 __result, __alloc);
758 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__result,
759 __alloc);
760 __result = __mid; // Everything up to __mid is now guarded.
761 __result = std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
762 __guard.release();
763 return __result;
764 }
765
766 // __uninitialized_fill_move
767 // Fills [result, mid) with x, and moves [first, last) into
768 // [mid, mid + (last - first)).
769 template<typename _ForwardIterator, typename _Tp, typename _InputIterator,
770 typename _Allocator>
771 inline _ForwardIterator
772 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
773 const _Tp& __x, _InputIterator __first,
774 _InputIterator __last, _Allocator& __alloc)
775 {
776 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
777 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__result,
778 __alloc);
779 __result = __mid; // Everything up to __mid is now guarded.
780 __result = std::__uninitialized_move_a(__first, __last, __mid, __alloc);
781 __guard.release();
782 return __result;
783 }
784
785 // __uninitialized_move_fill
786 // Moves [first1, last1) into [first2, first2 + (last1 - first1)), and
787 // fills [first2 + (last1 - first1), last2) with x.
788 template<typename _InputIterator, typename _ForwardIterator, typename _Tp,
789 typename _Allocator>
790 inline void
791 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
792 _ForwardIterator __first2,
793 _ForwardIterator __last2, const _Tp& __x,
794 _Allocator& __alloc)
795 {
796 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
797 __first2,
798 __alloc);
799 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__first2,
800 __alloc);
801 __first2 = __mid2; // Everything up to __mid2 is now guarded.
802 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
803 __guard.release();
804 }
805
806 /// @endcond
807
808#if __cplusplus >= 201103L
809 /// @cond undocumented
810
811 // Extensions: __uninitialized_default, __uninitialized_default_n,
812 // __uninitialized_default_a, __uninitialized_default_n_a.
813
814 template<bool _TrivialValueType>
815 struct __uninitialized_default_1
816 {
817 template<typename _ForwardIterator>
818 static void
819 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
820 {
821 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
822 for (; __first != __last; ++__first)
824 __guard.release();
825 }
826 };
827
828 template<>
829 struct __uninitialized_default_1<true>
830 {
831 template<typename _ForwardIterator>
832 static void
833 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
834 {
835 if (__first == __last)
836 return;
837
838 typename iterator_traits<_ForwardIterator>::value_type* __val
839 = std::__addressof(*__first);
840 std::_Construct(__val);
841 if (++__first != __last)
842 std::fill(__first, __last, *__val);
843 }
844 };
845
846 template<bool _TrivialValueType>
847 struct __uninitialized_default_n_1
848 {
849 template<typename _ForwardIterator, typename _Size>
850 _GLIBCXX20_CONSTEXPR
851 static _ForwardIterator
852 __uninit_default_n(_ForwardIterator __first, _Size __n)
853 {
854 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
855 for (; __n > 0; --__n, (void) ++__first)
857 __guard.release();
858 return __first;
859 }
860 };
861
862 template<>
863 struct __uninitialized_default_n_1<true>
864 {
865 template<typename _ForwardIterator, typename _Size>
866 _GLIBCXX20_CONSTEXPR
867 static _ForwardIterator
868 __uninit_default_n(_ForwardIterator __first, _Size __n)
869 {
870 if (__n > 0)
871 {
872 typename iterator_traits<_ForwardIterator>::value_type* __val
873 = std::__addressof(*__first);
874 std::_Construct(__val);
875 ++__first;
876 __first = std::fill_n(__first, __n - 1, *__val);
877 }
878 return __first;
879 }
880 };
881
882 // __uninitialized_default
883 // Fills [first, last) with value-initialized value_types.
884 template<typename _ForwardIterator>
885 inline void
886 __uninitialized_default(_ForwardIterator __first,
887 _ForwardIterator __last)
888 {
890 _ValueType;
891 // trivial types can have deleted assignment
892 const bool __assignable = is_copy_assignable<_ValueType>::value;
893
894 std::__uninitialized_default_1<__is_trivial(_ValueType)
895 && __assignable>::
896 __uninit_default(__first, __last);
897 }
898
899 // __uninitialized_default_n
900 // Fills [first, first + n) with value-initialized value_types.
901 template<typename _ForwardIterator, typename _Size>
902 _GLIBCXX20_CONSTEXPR
903 inline _ForwardIterator
904 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
905 {
906#ifdef __cpp_lib_is_constant_evaluated
907 if (std::is_constant_evaluated())
908 return __uninitialized_default_n_1<false>::
909 __uninit_default_n(__first, __n);
910#endif
911
913 _ValueType;
914 // See uninitialized_fill_n for the conditions for using std::fill_n.
915 constexpr bool __can_fill
916 = __and_<is_integral<_Size>, is_copy_assignable<_ValueType>>::value;
917
918 return __uninitialized_default_n_1<__is_trivial(_ValueType)
919 && __can_fill>::
920 __uninit_default_n(__first, __n);
921 }
922
923
924 // __uninitialized_default_a
925 // Fills [first, last) with value_types constructed by the allocator
926 // alloc, with no arguments passed to the construct call.
927 template<typename _ForwardIterator, typename _Allocator>
928 void
929 __uninitialized_default_a(_ForwardIterator __first,
930 _ForwardIterator __last,
931 _Allocator& __alloc)
932 {
933 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__first,
934 __alloc);
935 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
936 for (; __first != __last; ++__first)
937 __traits::construct(__alloc, std::__addressof(*__first));
938 __guard.release();
939 }
940
941#if _GLIBCXX_HOSTED
942 template<typename _ForwardIterator, typename _Tp>
943 inline void
944 __uninitialized_default_a(_ForwardIterator __first,
945 _ForwardIterator __last,
947 { std::__uninitialized_default(__first, __last); }
948#endif
949
950 // __uninitialized_default_n_a
951 // Fills [first, first + n) with value_types constructed by the allocator
952 // alloc, with no arguments passed to the construct call.
953 template<typename _ForwardIterator, typename _Size, typename _Allocator>
954 _GLIBCXX20_CONSTEXPR _ForwardIterator
955 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
956 _Allocator& __alloc)
957 {
958 _UninitDestroyGuard<_ForwardIterator, _Allocator> __guard(__first,
959 __alloc);
960 typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
961 for (; __n > 0; --__n, (void) ++__first)
962 __traits::construct(__alloc, std::__addressof(*__first));
963 __guard.release();
964 return __first;
965 }
966
967#if _GLIBCXX_HOSTED
968 // __uninitialized_default_n_a specialization for std::allocator,
969 // which ignores the allocator and value-initializes the elements.
970 template<typename _ForwardIterator, typename _Size, typename _Tp>
971 _GLIBCXX20_CONSTEXPR
972 inline _ForwardIterator
973 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
975 { return std::__uninitialized_default_n(__first, __n); }
976#endif
977
978 template<bool _TrivialValueType>
979 struct __uninitialized_default_novalue_1
980 {
981 template<typename _ForwardIterator>
982 static void
983 __uninit_default_novalue(_ForwardIterator __first,
984 _ForwardIterator __last)
985 {
986 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
987 for (; __first != __last; ++__first)
988 std::_Construct_novalue(std::__addressof(*__first));
989 __guard.release();
990 }
991 };
992
993 template<>
994 struct __uninitialized_default_novalue_1<true>
995 {
996 template<typename _ForwardIterator>
997 static void
998 __uninit_default_novalue(_ForwardIterator, _ForwardIterator)
999 {
1000 }
1001 };
1002
1003 template<bool _TrivialValueType>
1004 struct __uninitialized_default_novalue_n_1
1005 {
1006 template<typename _ForwardIterator, typename _Size>
1007 static _ForwardIterator
1008 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
1009 {
1010 _UninitDestroyGuard<_ForwardIterator> __guard(__first);
1011 for (; __n > 0; --__n, (void) ++__first)
1012 std::_Construct_novalue(std::__addressof(*__first));
1013 __guard.release();
1014 return __first;
1015 }
1016 };
1017
1018 template<>
1019 struct __uninitialized_default_novalue_n_1<true>
1020 {
1021 template<typename _ForwardIterator, typename _Size>
1022 static _ForwardIterator
1023 __uninit_default_novalue_n(_ForwardIterator __first, _Size __n)
1024 { return std::next(__first, __n); }
1025 };
1026
1027 // __uninitialized_default_novalue
1028 // Fills [first, last) with default-initialized value_types.
1029 template<typename _ForwardIterator>
1030 inline void
1031 __uninitialized_default_novalue(_ForwardIterator __first,
1032 _ForwardIterator __last)
1033 {
1035 _ValueType;
1036
1037 std::__uninitialized_default_novalue_1<
1039 __uninit_default_novalue(__first, __last);
1040 }
1041
1042 // __uninitialized_default_novalue_n
1043 // Fills [first, first + n) with default-initialized value_types.
1044 template<typename _ForwardIterator, typename _Size>
1045 inline _ForwardIterator
1046 __uninitialized_default_novalue_n(_ForwardIterator __first, _Size __n)
1047 {
1049 _ValueType;
1050
1051 return __uninitialized_default_novalue_n_1<
1053 __uninit_default_novalue_n(__first, __n);
1054 }
1055
1056 template<typename _InputIterator, typename _Size,
1057 typename _ForwardIterator>
1058 _ForwardIterator
1059 __uninitialized_copy_n(_InputIterator __first, _Size __n,
1060 _ForwardIterator __result, input_iterator_tag)
1061 {
1062 _UninitDestroyGuard<_ForwardIterator> __guard(__result);
1063 for (; __n > 0; --__n, (void) ++__first, ++__result)
1064 std::_Construct(std::__addressof(*__result), *__first);
1065 __guard.release();
1066 return __result;
1067 }
1068
1069 template<typename _RandomAccessIterator, typename _Size,
1070 typename _ForwardIterator>
1071 inline _ForwardIterator
1072 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
1073 _ForwardIterator __result,
1075 { return std::uninitialized_copy(__first, __first + __n, __result); }
1076
1077 template<typename _InputIterator, typename _Size,
1078 typename _ForwardIterator>
1080 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
1081 _ForwardIterator __result, input_iterator_tag)
1082 {
1083 _UninitDestroyGuard<_ForwardIterator> __guard(__result);
1084 for (; __n > 0; --__n, (void) ++__first, ++__result)
1085 std::_Construct(std::__addressof(*__result), *__first);
1086 __guard.release();
1087 return {__first, __result};
1088 }
1089
1090 template<typename _RandomAccessIterator, typename _Size,
1091 typename _ForwardIterator>
1093 __uninitialized_copy_n_pair(_RandomAccessIterator __first, _Size __n,
1094 _ForwardIterator __result,
1096 {
1097 auto __second_res = uninitialized_copy(__first, __first + __n, __result);
1098 auto __first_res = std::next(__first, __n);
1099 return {__first_res, __second_res};
1100 }
1101
1102 /// @endcond
1103
1104 /**
1105 * @brief Copies the range [first,first+n) into result.
1106 * @param __first An input iterator.
1107 * @param __n The number of elements to copy.
1108 * @param __result An output iterator.
1109 * @return __result + __n
1110 * @since C++11
1111 *
1112 * Like copy_n(), but does not require an initialized output range.
1113 */
1114 template<typename _InputIterator, typename _Size, typename _ForwardIterator>
1115 inline _ForwardIterator
1116 uninitialized_copy_n(_InputIterator __first, _Size __n,
1117 _ForwardIterator __result)
1118 { return std::__uninitialized_copy_n(__first, __n, __result,
1119 std::__iterator_category(__first)); }
1120
1121 /// @cond undocumented
1122 template<typename _InputIterator, typename _Size, typename _ForwardIterator>
1124 __uninitialized_copy_n_pair(_InputIterator __first, _Size __n,
1125 _ForwardIterator __result)
1126 {
1127 return
1128 std::__uninitialized_copy_n_pair(__first, __n, __result,
1129 std::__iterator_category(__first));
1130 }
1131 /// @endcond
1132#endif
1133
1134#ifdef __glibcxx_raw_memory_algorithms // C++ >= 17
1135 /**
1136 * @brief Default-initializes objects in the range [first,last).
1137 * @param __first A forward iterator.
1138 * @param __last A forward iterator.
1139 * @since C++17
1140 */
1141 template <typename _ForwardIterator>
1142 inline void
1143 uninitialized_default_construct(_ForwardIterator __first,
1144 _ForwardIterator __last)
1145 {
1146 std::__uninitialized_default_novalue(__first, __last);
1147 }
1148
1149 /**
1150 * @brief Default-initializes objects in the range [first,first+count).
1151 * @param __first A forward iterator.
1152 * @param __count The number of objects to construct.
1153 * @return __first + __count
1154 * @since C++17
1155 */
1156 template <typename _ForwardIterator, typename _Size>
1157 inline _ForwardIterator
1158 uninitialized_default_construct_n(_ForwardIterator __first, _Size __count)
1159 {
1160 return std::__uninitialized_default_novalue_n(__first, __count);
1161 }
1162
1163 /**
1164 * @brief Value-initializes objects in the range [first,last).
1165 * @param __first A forward iterator.
1166 * @param __last A forward iterator.
1167 * @since C++17
1168 */
1169 template <typename _ForwardIterator>
1170 inline void
1171 uninitialized_value_construct(_ForwardIterator __first,
1172 _ForwardIterator __last)
1173 {
1174 return std::__uninitialized_default(__first, __last);
1175 }
1176
1177 /**
1178 * @brief Value-initializes objects in the range [first,first+count).
1179 * @param __first A forward iterator.
1180 * @param __count The number of objects to construct.
1181 * @return __result + __count
1182 * @since C++17
1183 */
1184 template <typename _ForwardIterator, typename _Size>
1185 inline _ForwardIterator
1186 uninitialized_value_construct_n(_ForwardIterator __first, _Size __count)
1187 {
1188 return std::__uninitialized_default_n(__first, __count);
1189 }
1190
1191 /**
1192 * @brief Move-construct from the range [first,last) into result.
1193 * @param __first An input iterator.
1194 * @param __last An input iterator.
1195 * @param __result An output iterator.
1196 * @return __result + (__first - __last)
1197 * @since C++17
1198 */
1199 template <typename _InputIterator, typename _ForwardIterator>
1200 inline _ForwardIterator
1201 uninitialized_move(_InputIterator __first, _InputIterator __last,
1202 _ForwardIterator __result)
1203 {
1205 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1206 _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result);
1207 }
1208
1209 /**
1210 * @brief Move-construct from the range [first,first+count) into result.
1211 * @param __first An input iterator.
1212 * @param __count The number of objects to initialize.
1213 * @param __result An output iterator.
1214 * @return __result + __count
1215 * @since C++17
1216 */
1217 template <typename _InputIterator, typename _Size, typename _ForwardIterator>
1219 uninitialized_move_n(_InputIterator __first, _Size __count,
1220 _ForwardIterator __result)
1221 {
1222 auto __res = std::__uninitialized_copy_n_pair
1223 (_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
1224 __count, __result);
1225 return {__res.first.base(), __res.second};
1226 }
1227#endif // __glibcxx_raw_memory_algorithms
1228
1229#if __cplusplus >= 201103L
1230 /// @cond undocumented
1231
1232 template<typename _Tp, typename _Up, typename _Allocator>
1233 _GLIBCXX20_CONSTEXPR
1234 inline void
1235 __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig,
1236 _Allocator& __alloc)
1237 noexcept(noexcept(std::allocator_traits<_Allocator>::construct(__alloc,
1238 __dest, std::move(*__orig)))
1240 __alloc, std::__addressof(*__orig))))
1241 {
1242 typedef std::allocator_traits<_Allocator> __traits;
1243 __traits::construct(__alloc, __dest, std::move(*__orig));
1244 __traits::destroy(__alloc, std::__addressof(*__orig));
1245 }
1246
1247 // This class may be specialized for specific types.
1248 // Also known as is_trivially_relocatable.
1249 template<typename _Tp, typename = void>
1250 struct __is_bitwise_relocatable
1251 : __bool_constant<__is_trivial(_Tp)>
1252 { };
1253
1254 template <typename _InputIterator, typename _ForwardIterator,
1255 typename _Allocator>
1256 _GLIBCXX20_CONSTEXPR
1257 inline _ForwardIterator
1258 __relocate_a_1(_InputIterator __first, _InputIterator __last,
1259 _ForwardIterator __result, _Allocator& __alloc)
1260 noexcept(noexcept(std::__relocate_object_a(std::addressof(*__result),
1261 std::addressof(*__first),
1262 __alloc)))
1263 {
1265 _ValueType;
1267 _ValueType2;
1268 static_assert(std::is_same<_ValueType, _ValueType2>::value,
1269 "relocation is only possible for values of the same type");
1270 _ForwardIterator __cur = __result;
1271 for (; __first != __last; ++__first, (void)++__cur)
1272 std::__relocate_object_a(std::__addressof(*__cur),
1273 std::__addressof(*__first), __alloc);
1274 return __cur;
1275 }
1276
1277#if _GLIBCXX_HOSTED
1278 template <typename _Tp, typename _Up>
1279 _GLIBCXX20_CONSTEXPR
1280 inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
1281 __relocate_a_1(_Tp* __first, _Tp* __last,
1282 _Tp* __result,
1283 [[__maybe_unused__]] allocator<_Up>& __alloc) noexcept
1284 {
1285 ptrdiff_t __count = __last - __first;
1286 if (__count > 0)
1287 {
1288#ifdef __cpp_lib_is_constant_evaluated
1289 if (std::is_constant_evaluated())
1290 {
1291 // Can't use memcpy. Wrap the pointer so that __relocate_a_1
1292 // resolves to the non-trivial overload above.
1293 __gnu_cxx::__normal_iterator<_Tp*, void> __out(__result);
1294 __out = std::__relocate_a_1(__first, __last, __out, __alloc);
1295 return __out.base();
1296 }
1297#endif
1298 __builtin_memcpy(__result, __first, __count * sizeof(_Tp));
1299 }
1300 return __result + __count;
1301 }
1302#endif
1303
1304 template <typename _InputIterator, typename _ForwardIterator,
1305 typename _Allocator>
1306 _GLIBCXX20_CONSTEXPR
1307 inline _ForwardIterator
1308 __relocate_a(_InputIterator __first, _InputIterator __last,
1309 _ForwardIterator __result, _Allocator& __alloc)
1310 noexcept(noexcept(__relocate_a_1(std::__niter_base(__first),
1311 std::__niter_base(__last),
1312 std::__niter_base(__result), __alloc)))
1313 {
1314 return std::__relocate_a_1(std::__niter_base(__first),
1315 std::__niter_base(__last),
1316 std::__niter_base(__result), __alloc);
1317 }
1318
1319 /// @endcond
1320#endif // C++11
1321
1322 /// @} group memory
1323
1324_GLIBCXX_END_NAMESPACE_VERSION
1325} // namespace
1326
1327#endif /* _STL_UNINITIALIZED_H */
_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_value_construct_n(_ForwardIterator __first, _Size __count)
Value-initializes objects in the range [first,first+count).
_ForwardIterator uninitialized_move(_InputIterator __first, _InputIterator __last, _ForwardIterator __result)
Move-construct from 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).
_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __count)
Default-initializes objects in the range [first,first+count).
void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last)
Default-initializes objects in the range [first,last).
_ForwardIterator uninitialized_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result)
Copies the range [first,last) into result.
void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last)
Value-initializes objects in the range [first,last).
pair< _InputIterator, _ForwardIterator > uninitialized_move_n(_InputIterator __first, _Size __count, _ForwardIterator __result)
Move-construct from the range [first,first+count) into result.
constexpr _Tp * to_address(_Tp *__ptr) noexcept
Obtain address referenced by a pointer to an object.
Definition ptr_traits.h:232
typename remove_pointer< _Tp >::type remove_pointer_t
Alias template for remove_pointer.
Definition type_traits:2246
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs are equal iff their members are equal.
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...
Definition move.h:176
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition move.h:138
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Definition move.h:52
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr void _Construct(_Tp *__p, _Args &&... __args)
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
constexpr void _Destroy(_ForwardIterator __first, _ForwardIterator __last)
is_integral
Definition type_traits:467
is_pointer
Definition type_traits:554
is_copy_assignable
Definition type_traits:1286
is_trivially_default_constructible
Definition type_traits:1354
Uniform interface to all allocator types.
static constexpr void construct(_Alloc &__a, _Tp *__p, _Args &&... __args) noexcept(_S_nothrow_construct< _Tp, _Args... >())
Construct an object of type _Tp
static constexpr void destroy(_Alloc &__a, _Tp *__p) noexcept(_S_nothrow_destroy< _Tp >())
Destroy an object of type _Tp.
The standard allocator, as per C++03 [20.4.1].
Definition allocator.h:134
Struct holding two objects of arbitrary type.
Definition stl_pair.h:286
Marking input iterators.
Random-access iterators support a superset of bidirectional iterator operations.
Traits class for iterators.
Uniform interface to C++98 and C++11 allocators.