56#ifndef _STL_CONSTRUCT_H
57#define _STL_CONSTRUCT_H 1
73namespace std _GLIBCXX_VISIBILITY(default)
75_GLIBCXX_BEGIN_NAMESPACE_VERSION
77#if __glibcxx_raw_memory_algorithms
78 template <
typename _Tp>
79 _GLIBCXX20_CONSTEXPR
inline void
80 destroy_at(_Tp* __location)
82 if constexpr (__cplusplus > 201703L && is_array_v<_Tp>)
84 for (
auto& __x : *__location)
91#if __cpp_constexpr_dynamic_alloc
92 template<
typename _Tp,
typename... _Args>
93 requires (!is_unbounded_array_v<_Tp>)
94 &&
requires { ::new((
void*)0) _Tp(std::declval<_Args>()...); }
96 construct_at(_Tp* __location, _Args&&... __args)
97 noexcept(
noexcept(::new((
void*)0) _Tp(std::declval<_Args>()...)))
99 void* __loc = __location;
102 if constexpr (is_array_v<_Tp>)
104 static_assert(
sizeof...(_Args) == 0,
"std::construct_at for array "
105 "types must not use any arguments to initialize the "
107 return ::new(__loc) _Tp[1]();
110 return ::new(__loc) _Tp(std::forward<_Args>(__args)...);
119#if __cplusplus >= 201103L
120 template<
typename _Tp,
typename... _Args>
125#if __cpp_constexpr_dynamic_alloc
126 if (std::__is_constant_evaluated())
129 std::construct_at(__p, std::forward<_Args>(__args)...);
133 ::new(
static_cast<void*
>(__p)) _Tp(std::forward<_Args>(__args)...);
136 template<
typename _T1,
typename _T2>
142 ::new(
static_cast<void*
>(__p)) _T1(__value);
146 template<
typename _T1>
148 _Construct_novalue(_T1* __p)
149 { ::new(
static_cast<void*
>(__p)) _T1; }
151 template<
typename _ForwardIterator>
152 _GLIBCXX20_CONSTEXPR
void
153 _Destroy(_ForwardIterator __first, _ForwardIterator __last);
158 template<
typename _Tp>
159 _GLIBCXX14_CONSTEXPR
inline void
162#if __cpp_constexpr_dynamic_alloc
163 std::destroy_at(__pointer);
169#pragma GCC diagnostic push
170#pragma GCC diagnostic ignored "-Wc++17-extensions"
172#if __cplusplus < 201103L
176 template<
typename _ForwardIterator>
177 static _GLIBCXX20_CONSTEXPR
void
178 __destroy(_ForwardIterator __first, _ForwardIterator __last)
180 for (; __first != __last; ++__first)
186 struct _Destroy_aux<true>
188 template<
typename _ForwardIterator>
190 __destroy(_ForwardIterator, _ForwardIterator) { }
199 template<
typename _ForwardIterator>
200 _GLIBCXX20_CONSTEXPR
inline void
201 _Destroy(_ForwardIterator __first, _ForwardIterator __last)
205#if __cplusplus >= 201103L
208 "value type is destructible");
209 if constexpr (!__has_trivial_destructor(_Value_type))
210 for (; __first != __last; ++__first)
212#if __cpp_constexpr_dynamic_alloc
213 else if (std::__is_constant_evaluated())
214 for (; __first != __last; ++__first)
218 std::_Destroy_aux<__has_trivial_destructor(_Value_type)>::
219 __destroy(__first, __last);
223#if __cplusplus < 201103L
225 struct _Destroy_n_aux
227 template<
typename _ForwardIterator,
typename _Size>
228 static _GLIBCXX20_CONSTEXPR _ForwardIterator
229 __destroy_n(_ForwardIterator __first, _Size __count)
231 for (; __count > 0; (void)++__first, --__count)
238 struct _Destroy_n_aux<true>
240 template<
typename _ForwardIterator,
typename _Size>
241 static _ForwardIterator
242 __destroy_n(_ForwardIterator __first, _Size __count)
255 template<
typename _ForwardIterator,
typename _Size>
256 _GLIBCXX20_CONSTEXPR
inline _ForwardIterator
261#if __cplusplus >= 201103L
264 "value type is destructible");
265 if constexpr (!__has_trivial_destructor(_Value_type))
266 for (; __count > 0; (void)++__first, --__count)
268#if __cpp_constexpr_dynamic_alloc
269 else if (std::__is_constant_evaluated())
270 for (; __count > 0; (void)++__first, --__count)
277 return std::_Destroy_n_aux<__has_trivial_destructor(_Value_type)>::
278 __destroy_n(__first, __count);
281#pragma GCC diagnostic pop
283#if __glibcxx_raw_memory_algorithms
284 template <
typename _ForwardIterator>
285 _GLIBCXX20_CONSTEXPR
inline void
286 destroy(_ForwardIterator __first, _ForwardIterator __last)
291 template <
typename _ForwardIterator,
typename _Size>
292 _GLIBCXX20_CONSTEXPR
inline _ForwardIterator
293 destroy_n(_ForwardIterator __first, _Size __count)
299_GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
constexpr _ForwardIterator _Destroy_n(_ForwardIterator __first, _Size __count)
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)
Traits class for iterators.