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
100namespace std _GLIBCXX_VISIBILITY(default)
102_GLIBCXX_BEGIN_NAMESPACE_VERSION
123align(
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);
165template <
typename _Tp>
182#if __cplusplus > 201703L
190 template<
size_t _Align,
class _Tp>
191 [[nodiscard,__gnu__::__always_inline__]]
192 constexpr _Tp* assume_aligned(_Tp* __ptr)
194 static_assert(std::has_single_bit(_Align));
195 _GLIBCXX_DEBUG_ASSERT((std::uintptr_t)__ptr % _Align == 0);
196 return static_cast<_Tp*
>(__builtin_assume_aligned(__ptr, _Align));
200#if __cplusplus > 201703L
201 template<
typename _Tp>
203 template<
typename _Tp,
typename _Up>
204 struct __is_pair<pair<_Tp, _Up>> :
true_type { };
205 template<
typename _Tp,
typename _Up>
206 struct __is_pair<const pair<_Tp, _Up>> :
true_type { };
211 template<
typename _Tp,
typename __ = _Require<__not_<__is_pair<_Tp>>>,
212 typename _Alloc,
typename... _Args>
214 __uses_alloc_args(
const _Alloc& __a, _Args&&... __args)
noexcept
216 if constexpr (uses_allocator_v<remove_cv_t<_Tp>, _Alloc>)
218 if constexpr (is_constructible_v<_Tp, allocator_arg_t,
219 const _Alloc&, _Args...>)
221 return tuple<allocator_arg_t,
const _Alloc&, _Args&&...>(
222 allocator_arg, __a, std::forward<_Args>(__args)...);
226 static_assert(is_constructible_v<_Tp, _Args...,
const _Alloc&>,
227 "construction with an allocator must be possible"
228 " if uses_allocator is true");
230 return tuple<_Args&&...,
const _Alloc&>(
231 std::forward<_Args>(__args)..., __a);
236 static_assert(is_constructible_v<_Tp, _Args...>);
238 return tuple<_Args&&...>(std::forward<_Args>(__args)...);
243 template<
typename _Tp>
244 concept _Std_pair = __is_pair<_Tp>::value;
249# define _GLIBCXX_STD_PAIR_CONSTRAINT(T) _Std_pair T
250# define _GLIBCXX_STD_PAIR_CONSTRAINT_(T) _Std_pair T
252# define _GLIBCXX_STD_PAIR_CONSTRAINT(T) \
253 typename T, typename __ = _Require<__is_pair<T>>
254# define _GLIBCXX_STD_PAIR_CONSTRAINT_(T) typename T, typename
257 template<
typename _Tp,
259 typename __ = _Require<__not_<__is_pair<_Tp>>>,
261 typename _Alloc,
typename... _Args>
263 uses_allocator_construction_args(
const _Alloc& __a,
264 _Args&&... __args)
noexcept
266 requires (! _Std_pair<_Tp>)
269 return std::__uses_alloc_args<_Tp>(__a, std::forward<_Args>(__args)...);
272 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp),
typename _Alloc,
273 typename _Tuple1,
typename _Tuple2>
275 uses_allocator_construction_args(
const _Alloc& __a, piecewise_construct_t,
276 _Tuple1&& __x, _Tuple2&& __y)
noexcept;
278 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp),
typename _Alloc>
280 uses_allocator_construction_args(
const _Alloc&)
noexcept;
282 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp),
typename _Alloc,
283 typename _Up,
typename _Vp>
285 uses_allocator_construction_args(
const _Alloc&, _Up&&, _Vp&&) noexcept;
287 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
288 typename _Up, typename _Vp>
290 uses_allocator_construction_args(const _Alloc&,
291 const pair<_Up, _Vp>&) noexcept;
293 template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
294 typename _Up, typename _Vp>
296 uses_allocator_construction_args(const _Alloc&, pair<_Up, _Vp>&&) noexcept;
298 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp), typename _Alloc,
299 typename _Tuple1, typename _Tuple2>
301 uses_allocator_construction_args(const _Alloc& __a, piecewise_construct_t,
302 _Tuple1&& __x, _Tuple2&& __y) noexcept
304 using _Tp1 =
typename _Tp::first_type;
305 using _Tp2 =
typename _Tp::second_type;
308 std::apply([&__a](
auto&&... __args1) {
309 return std::uses_allocator_construction_args<_Tp1>(
311 }, std::forward<_Tuple1>(__x)),
312 std::apply([&__a](
auto&&... __args2) {
313 return std::uses_allocator_construction_args<_Tp2>(
315 }, std::forward<_Tuple2>(__y)));
318 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc>
320 uses_allocator_construction_args(
const _Alloc& __a)
noexcept
322 using _Tp1 =
typename _Tp::first_type;
323 using _Tp2 =
typename _Tp::second_type;
326 std::uses_allocator_construction_args<_Tp1>(__a),
327 std::uses_allocator_construction_args<_Tp2>(__a));
330 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc,
331 typename _Up,
typename _Vp>
333 uses_allocator_construction_args(
const _Alloc& __a, _Up&& __u, _Vp&& __v)
336 using _Tp1 =
typename _Tp::first_type;
337 using _Tp2 =
typename _Tp::second_type;
340 std::uses_allocator_construction_args<_Tp1>(__a,
341 std::forward<_Up>(__u)),
342 std::uses_allocator_construction_args<_Tp2>(__a,
343 std::forward<_Vp>(__v)));
346 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc,
347 typename _Up,
typename _Vp>
349 uses_allocator_construction_args(
const _Alloc& __a,
350 const 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, __pr.first),
357 std::uses_allocator_construction_args<_Tp2>(__a, __pr.second));
360 template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp),
typename _Alloc,
361 typename _Up,
typename _Vp>
363 uses_allocator_construction_args(
const _Alloc& __a,
364 pair<_Up, _Vp>&& __pr)
noexcept
366 using _Tp1 =
typename _Tp::first_type;
367 using _Tp2 =
typename _Tp::second_type;
370 std::uses_allocator_construction_args<_Tp1>(__a,
372 std::uses_allocator_construction_args<_Tp2>(__a,
376 template<
typename _Tp,
typename _Alloc,
typename... _Args>
378 make_obj_using_allocator(
const _Alloc& __a, _Args&&... __args)
380 return std::make_from_tuple<_Tp>(
381 std::uses_allocator_construction_args<_Tp>(__a,
382 std::forward<_Args>(__args)...));
385 template<
typename _Tp,
typename _Alloc,
typename... _Args>
387 uninitialized_construct_using_allocator(_Tp* __p,
const _Alloc& __a,
390 return std::apply([&](
auto&&... __xs) {
391 return std::construct_at(__p,
std::forward<
decltype(__xs)>(__xs)...);
392 }, std::uses_allocator_construction_args<_Tp>(__a,
393 std::forward<_Args>(__args)...));
399_GLIBCXX_END_NAMESPACE_VERSION
403#if __cplusplus > 201402L
405# if _PSTL_EXECUTION_POLICIES_DEFINED
407# include <pstl/glue_memory_impl.h>
410# include <pstl/glue_memory_defs.h>
414# define __cpp_lib_parallel_algorithm 201603L
void * align(size_t __align, size_t __size, void *&__ptr, size_t &__space) noexcept
Fit aligned storage in buffer.
void declare_reachable(void *)
Inform a garbage collector that an object is still in use.
pointer_safety get_pointer_safety() noexcept
The type of pointer safety supported by the implementation.
void undeclare_no_pointers(char *, size_t)
Unregister a range previously registered with declare_no_pointers.
void declare_no_pointers(char *, size_t)
Inform a garbage collector that a region of memory need not be traced.
pointer_safety
Constants representing the different types of pointer safety.
_Tp * undeclare_reachable(_Tp *__p)
Unregister an object previously registered with declare_reachable.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr piecewise_construct_t piecewise_construct
Tag for piecewise construction of std::pair objects.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.