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>
149 _Construct_novalue(_T1* __p)
150 { ::new(
static_cast<void*
>(__p)) _T1; }
152 template<
typename _ForwardIterator>
153 _GLIBCXX20_CONSTEXPR
void
154 _Destroy(_ForwardIterator __first, _ForwardIterator __last);
159 template<
typename _Tp>
160 _GLIBCXX14_CONSTEXPR
inline void
163#if __cpp_constexpr_dynamic_alloc
164 std::destroy_at(__pointer);
170#pragma GCC diagnostic push
171#pragma GCC diagnostic ignored "-Wc++17-extensions"
173#if __cplusplus < 201103L
177 template<
typename _ForwardIterator>
178 static _GLIBCXX20_CONSTEXPR
void
179 __destroy(_ForwardIterator __first, _ForwardIterator __last)
181 for (; __first != __last; ++__first)
187 struct _Destroy_aux<true>
189 template<
typename _ForwardIterator>
191 __destroy(_ForwardIterator, _ForwardIterator) { }
200 template<
typename _ForwardIterator>
201 _GLIBCXX20_CONSTEXPR
inline void
202 _Destroy(_ForwardIterator __first, _ForwardIterator __last)
206#if __cplusplus >= 201103L
209 "value type is destructible");
210 if constexpr (!__has_trivial_destructor(_Value_type))
211 for (; __first != __last; ++__first)
213#if __cpp_constexpr_dynamic_alloc
214 else if (std::__is_constant_evaluated())
215 for (; __first != __last; ++__first)
219 std::_Destroy_aux<__has_trivial_destructor(_Value_type)>::
220 __destroy(__first, __last);
224#if __cplusplus < 201103L
226 struct _Destroy_n_aux
228 template<
typename _ForwardIterator,
typename _Size>
229 static _GLIBCXX20_CONSTEXPR _ForwardIterator
230 __destroy_n(_ForwardIterator __first, _Size __count)
232 for (; __count > 0; (void)++__first, --__count)
239 struct _Destroy_n_aux<true>
241 template<
typename _ForwardIterator,
typename _Size>
242 static _ForwardIterator
243 __destroy_n(_ForwardIterator __first, _Size __count)
256 template<
typename _ForwardIterator,
typename _Size>
257 _GLIBCXX20_CONSTEXPR
inline _ForwardIterator
262#if __cplusplus >= 201103L
265 "value type is destructible");
266 if constexpr (!__has_trivial_destructor(_Value_type))
267 for (; __count > 0; (void)++__first, --__count)
269#if __cpp_constexpr_dynamic_alloc
270 else if (std::__is_constant_evaluated())
271 for (; __count > 0; (void)++__first, --__count)
278 return std::_Destroy_n_aux<__has_trivial_destructor(_Value_type)>::
279 __destroy_n(__first, __count);
282#pragma GCC diagnostic pop
284#if __glibcxx_raw_memory_algorithms
285 template <
typename _ForwardIterator>
286 _GLIBCXX20_CONSTEXPR
inline void
287 destroy(_ForwardIterator __first, _ForwardIterator __last)
292 template <
typename _ForwardIterator,
typename _Size>
293 _GLIBCXX20_CONSTEXPR
inline _ForwardIterator
294 destroy_n(_ForwardIterator __first, _Size __count)
300_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.