44 #ifndef _GLIBCXX_MEMORY
45 #define _GLIBCXX_MEMORY 1
47 #pragma GCC system_header
71 #if __cplusplus >= 201103L
79 # include <bits/uses_allocator.h>
84 # include <bits/shared_ptr.h>
86 # if _GLIBCXX_USE_DEPRECATED
93 #if __cplusplus >= 201103L
95 #if __cplusplus > 201703L
100 namespace std _GLIBCXX_VISIBILITY(default)
102 _GLIBCXX_BEGIN_NAMESPACE_VERSION
123 align(
size_t __align,
size_t __size,
void*& __ptr,
size_t& __space) noexcept
125 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
126 const auto __intptr =
reinterpret_cast<uintptr_t
>(__ptr);
129 static_assert(
sizeof(
size_t) >=
sizeof(
void*),
130 "std::size_t must be a suitable substitute for std::uintptr_t");
131 const auto __intptr =
reinterpret_cast<unsigned long long>(__ptr);
133 const auto __aligned = (__intptr - 1u + __align) & -__align;
134 const auto __diff = __aligned - __intptr;
135 if ((__size + __diff) > __space)
140 return __ptr =
reinterpret_cast<void*
>(__aligned);
165 template <
typename _Tp>
182 #if __cplusplus > 201703L
183 #define __cpp_lib_assume_aligned 201811L
194 template<
size_t _Align,
class _Tp>
195 [[nodiscard,__gnu__::__always_inline__]]
197 assume_aligned(_Tp* __ptr) noexcept
199 static_assert(std::has_single_bit(_Align));
200 if (std::is_constant_evaluated())
206 _GLIBCXX_DEBUG_ASSERT((std::uintptr_t)__ptr % _Align == 0);
207 return static_cast<_Tp*
>(__builtin_assume_aligned(__ptr, _Align));
212 #if __cplusplus > 201703L
213 template<
typename _Tp>
215 template<
typename _Tp,
typename _Up>
216 struct __is_pair<pair<_Tp, _Up>> :
true_type { };
217 template<
typename _Tp,
typename _Up>
218 struct __is_pair<const pair<_Tp, _Up>> :
true_type { };
223 template<
typename _Tp,
typename __ = _Require<__not_<__is_pair<_Tp>>>,
224 typename _Alloc,
typename... _Args>
226 __uses_alloc_args(
const _Alloc& __a, _Args&&... __args) noexcept
228 if constexpr (uses_allocator_v<remove_cv_t<_Tp>, _Alloc>)
230 if constexpr (is_constructible_v<_Tp, allocator_arg_t,
231 const _Alloc&, _Args...>)
233 return tuple<allocator_arg_t,
const _Alloc&, _Args&&...>(
234 allocator_arg, __a, std::forward<_Args>(__args)...);
238 static_assert(is_constructible_v<_Tp, _Args..., const _Alloc&>,
239 "construction with an allocator must be possible"
240 " if uses_allocator is true");
242 return tuple<_Args&&...,
const _Alloc&>(
243 std::forward<_Args>(__args)..., __a);
248 static_assert(is_constructible_v<_Tp, _Args...>);
250 return tuple<_Args&&...>(std::forward<_Args>(__args)...);
255 template<
typename _Tp>
256 concept _Std_pair = __is_pair<_Tp>::value;
261 # define _GLIBCXX_STD_PAIR_CONSTRAINT(T) _Std_pair T
262 # define _GLIBCXX_STD_PAIR_CONSTRAINT_(T) _Std_pair T
264 # define _GLIBCXX_STD_PAIR_CONSTRAINT(T) \
265 typename T, typename __ = _Require<__is_pair<T>>
266 # define _GLIBCXX_STD_PAIR_CONSTRAINT_(T) typename T, typename
269 template<
typename _Tp,
271 typename __ = _Require<__not_<__is_pair<_Tp>>>,
273 typename _Alloc,
typename... _Args>
275 uses_allocator_construction_args(
const _Alloc& __a,
276 _Args&&... __args) noexcept
278 requires (! _Std_pair<_Tp>)
281 return std::__uses_alloc_args<_Tp>(__a, std::forward<_Args>(__args)...);
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 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc>
292 uses_allocator_construction_args(const _Alloc&) noexcept;
294 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
295 typename _Up, typename _Vp>
297 uses_allocator_construction_args(const _Alloc&, _Up&&, _Vp&&) noexcept;
299 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
300 typename _Up, typename _Vp>
302 uses_allocator_construction_args(const _Alloc&,
303 const pair<_Up, _Vp>&) noexcept;
305 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
306 typename _Up, typename _Vp>
308 uses_allocator_construction_args(const _Alloc&, pair<_Up, _Vp>&&) noexcept;
310 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp), typename _Alloc,
311 typename _Tuple1, typename _Tuple2>
313 uses_allocator_construction_args(const _Alloc& __a, piecewise_construct_t,
314 _Tuple1&& __x, _Tuple2&& __y) noexcept
316 using _Tp1 =
typename _Tp::first_type;
317 using _Tp2 =
typename _Tp::second_type;
320 std::apply([&__a](
auto&&... __args1) {
321 return std::uses_allocator_construction_args<_Tp1>(
322 __a, std::forward<decltype(__args1)>(__args1)...);
323 }, std::forward<_Tuple1>(__x)),
324 std::apply([&__a](
auto&&... __args2) {
325 return std::uses_allocator_construction_args<_Tp2>(
326 __a, std::forward<decltype(__args2)>(__args2)...);
327 }, std::forward<_Tuple2>(__y)));
330 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc>
332 uses_allocator_construction_args(
const _Alloc& __a) noexcept
334 using _Tp1 =
typename _Tp::first_type;
335 using _Tp2 =
typename _Tp::second_type;
338 std::uses_allocator_construction_args<_Tp1>(__a),
339 std::uses_allocator_construction_args<_Tp2>(__a));
342 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc,
343 typename _Up,
typename _Vp>
345 uses_allocator_construction_args(
const _Alloc& __a, _Up&& __u, _Vp&& __v)
348 using _Tp1 =
typename _Tp::first_type;
349 using _Tp2 =
typename _Tp::second_type;
352 std::uses_allocator_construction_args<_Tp1>(__a,
353 std::forward<_Up>(__u)),
354 std::uses_allocator_construction_args<_Tp2>(__a,
355 std::forward<_Vp>(__v)));
358 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc,
359 typename _Up,
typename _Vp>
361 uses_allocator_construction_args(
const _Alloc& __a,
362 const pair<_Up, _Vp>& __pr) noexcept
364 using _Tp1 =
typename _Tp::first_type;
365 using _Tp2 =
typename _Tp::second_type;
368 std::uses_allocator_construction_args<_Tp1>(__a, __pr.first),
369 std::uses_allocator_construction_args<_Tp2>(__a, __pr.second));
372 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc,
373 typename _Up,
typename _Vp>
375 uses_allocator_construction_args(
const _Alloc& __a,
376 pair<_Up, _Vp>&& __pr) noexcept
378 using _Tp1 =
typename _Tp::first_type;
379 using _Tp2 =
typename _Tp::second_type;
382 std::uses_allocator_construction_args<_Tp1>(__a,
384 std::uses_allocator_construction_args<_Tp2>(__a,
388 template<
typename _Tp,
typename _Alloc,
typename... _Args>
390 make_obj_using_allocator(
const _Alloc& __a, _Args&&... __args)
392 return std::make_from_tuple<_Tp>(
393 std::uses_allocator_construction_args<_Tp>(__a,
394 std::forward<_Args>(__args)...));
397 template<
typename _Tp,
typename _Alloc,
typename... _Args>
399 uninitialized_construct_using_allocator(_Tp* __p,
const _Alloc& __a,
402 return std::apply([&](
auto&&... __xs) {
403 return std::construct_at(__p,
std::forward<decltype(__xs)>(__xs)...);
404 }, std::uses_allocator_construction_args<_Tp>(__a,
405 std::forward<_Args>(__args)...));
411 _GLIBCXX_END_NAMESPACE_VERSION
415 #if __cplusplus > 201402L
417 # if _PSTL_EXECUTION_POLICIES_DEFINED
419 # include <pstl/glue_memory_impl.h>
422 # include <pstl/glue_memory_defs.h>
426 # define __cpp_lib_parallel_algorithm 201603L
_Tp * undeclare_reachable(_Tp *__p)
Unregister an object previously registered with declare_reachable.
void * align(size_t __align, size_t __size, void *&__ptr, size_t &__space) noexcept
Fit aligned storage in buffer.This function tries to fit __size bytes of storage with alignment __ali...
void declare_no_pointers(char *, size_t)
Inform a garbage collector that a region of memory need not be traced.
pointer_safety get_pointer_safety() noexcept
The type of pointer safety supported by the implementation.
void declare_reachable(void *)
Inform a garbage collector that an object is still in use.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
pointer_safety
Constants representing the different types of pointer safety.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
void undeclare_no_pointers(char *, size_t)
Unregister a range previously registered with declare_no_pointers.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
constexpr piecewise_construct_t piecewise_construct
Tag for piecewise construction of std::pair objects.