43 #ifndef _GLIBCXX_MEMORY
44 #define _GLIBCXX_MEMORY 1
46 #pragma GCC system_header
69 #if __cplusplus >= 201103L
77 # include <bits/uses_allocator.h>
81 # include <bits/shared_ptr.h>
83 # if _GLIBCXX_USE_DEPRECATED
90 #if __cplusplus >= 201103L
92 #if __cplusplus > 201703L
97 namespace std _GLIBCXX_VISIBILITY(default)
99 _GLIBCXX_BEGIN_NAMESPACE_VERSION
118 align(
size_t __align,
size_t __size,
void*& __ptr,
size_t& __space) noexcept
120 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
121 const auto __intptr =
reinterpret_cast<uintptr_t
>(__ptr);
124 static_assert(
sizeof(
size_t) >=
sizeof(
void*),
125 "std::size_t must be a suitable substitute for std::uintptr_t");
126 const auto __intptr =
reinterpret_cast<unsigned long long>(__ptr);
128 const auto __aligned = (__intptr - 1u + __align) & -__align;
129 const auto __diff = __aligned - __intptr;
130 if ((__size + __diff) > __space)
135 return __ptr =
reinterpret_cast<void*
>(__aligned);
141 enum class pointer_safety { relaxed, preferred, strict };
144 declare_reachable(
void*) { }
146 template <
typename _Tp>
148 undeclare_reachable(_Tp* __p) {
return __p; }
151 declare_no_pointers(
char*,
size_t) { }
154 undeclare_no_pointers(
char*,
size_t) { }
156 inline pointer_safety
157 get_pointer_safety() noexcept {
return pointer_safety::relaxed; }
159 #if __cplusplus > 201703L
160 #define __cpp_lib_assume_aligned 201811L
171 template<
size_t _Align,
class _Tp>
172 [[nodiscard,__gnu__::__always_inline__]]
174 assume_aligned(_Tp* __ptr) noexcept
176 static_assert(std::ispow2(_Align));
177 if (std::is_constant_evaluated())
183 _GLIBCXX_DEBUG_ASSERT((std::uintptr_t)__ptr % _Align == 0);
184 return static_cast<_Tp*
>(__builtin_assume_aligned(__ptr, _Align));
189 #if __cplusplus > 201703L
190 template<
typename _Tp>
192 template<
typename _Tp,
typename _Up>
193 struct __is_pair<pair<_Tp, _Up>> :
true_type { };
194 template<
typename _Tp,
typename _Up>
195 struct __is_pair<const pair<_Tp, _Up>> :
true_type { };
197 template<
typename _Tp,
typename __ = _Require<__not_<__is_pair<_Tp>>>,
198 typename _Alloc,
typename... _Args>
200 __uses_alloc_args(
const _Alloc& __a, _Args&&... __args) noexcept
202 if constexpr (uses_allocator_v<remove_cv_t<_Tp>, _Alloc>)
204 if constexpr (is_constructible_v<_Tp, allocator_arg_t,
205 const _Alloc&, _Args...>)
207 return tuple<allocator_arg_t,
const _Alloc&, _Args&&...>(
208 allocator_arg, __a, std::forward<_Args>(__args)...);
212 static_assert(is_constructible_v<_Tp, _Args..., const _Alloc&>,
213 "construction with an allocator must be possible"
214 " if uses_allocator is true");
216 return tuple<_Args&&...,
const _Alloc&>(
217 std::forward<_Args>(__args)..., __a);
222 static_assert(is_constructible_v<_Tp, _Args...>);
224 return tuple<_Args&&...>(std::forward<_Args>(__args)...);
229 template<
typename _Tp>
230 concept _Std_pair = __is_pair<_Tp>::value;
235 # define _GLIBCXX_STD_PAIR_CONSTRAINT(T) _Std_pair T
236 # define _GLIBCXX_STD_PAIR_CONSTRAINT_(T) _Std_pair T
238 # define _GLIBCXX_STD_PAIR_CONSTRAINT(T) \
239 typename T, typename __ = _Require<__is_pair<T>>
240 # define _GLIBCXX_STD_PAIR_CONSTRAINT_(T) typename T, typename
243 template<
typename _Tp,
245 typename __ = _Require<__not_<__is_pair<_Tp>>>,
247 typename _Alloc,
typename... _Args>
249 uses_allocator_construction_args(
const _Alloc& __a,
250 _Args&&... __args) noexcept
252 requires (! _Std_pair<_Tp>)
255 return std::__uses_alloc_args<_Tp>(__a, std::forward<_Args>(__args)...);
258 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp),
typename _Alloc,
259 typename _Tuple1,
typename _Tuple2>
261 uses_allocator_construction_args(
const _Alloc& __a, piecewise_construct_t,
262 _Tuple1&& __x, _Tuple2&& __y) noexcept;
264 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc>
266 uses_allocator_construction_args(const _Alloc&) noexcept;
268 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
269 typename _Up, typename _Vp>
271 uses_allocator_construction_args(const _Alloc&, _Up&&, _Vp&&) noexcept;
273 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
274 typename _Up, typename _Vp>
276 uses_allocator_construction_args(const _Alloc&,
277 const pair<_Up, _Vp>&) noexcept;
279 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
280 typename _Up, typename _Vp>
282 uses_allocator_construction_args(const _Alloc&, pair<_Up, _Vp>&&) noexcept;
284 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp), typename _Alloc,
285 typename _Tuple1, typename _Tuple2>
287 uses_allocator_construction_args(const _Alloc& __a, piecewise_construct_t,
288 _Tuple1&& __x, _Tuple2&& __y) noexcept
290 using _Tp1 =
typename _Tp::first_type;
291 using _Tp2 =
typename _Tp::second_type;
294 std::apply([&__a](
auto&&... __args1) {
295 return std::uses_allocator_construction_args<_Tp1>(
296 __a, std::forward<decltype(__args1)>(__args1)...);
297 }, std::forward<_Tuple1>(__x)),
298 std::apply([&__a](
auto&&... __args2) {
299 return std::uses_allocator_construction_args<_Tp2>(
300 __a, std::forward<decltype(__args2)>(__args2)...);
301 }, std::forward<_Tuple2>(__y)));
304 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc>
306 uses_allocator_construction_args(
const _Alloc& __a) noexcept
308 using _Tp1 =
typename _Tp::first_type;
309 using _Tp2 =
typename _Tp::second_type;
312 std::uses_allocator_construction_args<_Tp1>(__a),
313 std::uses_allocator_construction_args<_Tp2>(__a));
316 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc,
317 typename _Up,
typename _Vp>
319 uses_allocator_construction_args(
const _Alloc& __a, _Up&& __u, _Vp&& __v)
322 using _Tp1 =
typename _Tp::first_type;
323 using _Tp2 =
typename _Tp::second_type;
326 std::uses_allocator_construction_args<_Tp1>(__a,
327 std::forward<_Up>(__u)),
328 std::uses_allocator_construction_args<_Tp2>(__a,
329 std::forward<_Vp>(__v)));
332 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc,
333 typename _Up,
typename _Vp>
335 uses_allocator_construction_args(
const _Alloc& __a,
336 const pair<_Up, _Vp>& __pr) noexcept
338 using _Tp1 =
typename _Tp::first_type;
339 using _Tp2 =
typename _Tp::second_type;
342 std::uses_allocator_construction_args<_Tp1>(__a, __pr.first),
343 std::uses_allocator_construction_args<_Tp2>(__a, __pr.second));
346 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc,
347 typename _Up,
typename _Vp>
349 uses_allocator_construction_args(
const _Alloc& __a,
350 pair<_Up, _Vp>&& __pr) noexcept
352 using _Tp1 =
typename _Tp::first_type;
353 using _Tp2 =
typename _Tp::second_type;
356 std::uses_allocator_construction_args<_Tp1>(__a,
357 std::move(__pr).first),
358 std::uses_allocator_construction_args<_Tp2>(__a,
359 std::move(__pr).second));
362 template<
typename _Tp,
typename _Alloc,
typename... _Args>
364 make_obj_using_allocator(
const _Alloc& __a, _Args&&... __args)
366 return std::make_from_tuple<_Tp>(
367 std::uses_allocator_construction_args<_Tp>(__a,
368 std::forward<_Args>(__args)...));
371 template<
typename _Tp,
typename _Alloc,
typename... _Args>
373 uninitialized_construct_using_allocator(_Tp* __p,
const _Alloc& __a,
376 void* __vp =
const_cast<void*
>(
static_cast<const volatile void*
>(__p));
377 return ::new(__vp) _Tp(std::make_obj_using_allocator<_Tp>(__a,
378 std::
forward<_Args>(__args)...));
383 _GLIBCXX_END_NAMESPACE_VERSION
387 #if __cplusplus > 201402L
389 # if __PSTL_EXECUTION_POLICIES_DEFINED
391 # include <pstl/glue_memory_impl.h>
394 # include <pstl/glue_memory_defs.h>
398 # define __cpp_lib_parallel_algorithm 201603L
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
void * align(size_t __align, size_t __size, void *&__ptr, size_t &__space) noexcept
Fit aligned storage in buffer.
_GLIBCXX17_INLINE constexpr piecewise_construct_t piecewise_construct
piecewise_construct
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.