30 #ifndef _GLIBCXX_MEMORY_RESOURCE_H
31 #define _GLIBCXX_MEMORY_RESOURCE_H 1
33 #ifdef _GLIBCXX_SYSHDR
34 #pragma GCC system_header
37 #if __cplusplus >= 201703L
42 #include <bits/uses_allocator.h>
47 #if ! __glibcxx_make_obj_using_allocator
53 namespace std _GLIBCXX_VISIBILITY(default)
55 _GLIBCXX_BEGIN_NAMESPACE_VERSION
66 static constexpr
size_t _S_max_align =
alignof(max_align_t);
77 allocate(
size_t __bytes,
size_t __alignment = _S_max_align)
78 __attribute__((__returns_nonnull__,__alloc_size__(2),__alloc_align__(3)))
79 { return ::operator
new(__bytes, do_allocate(__bytes, __alignment)); }
82 deallocate(
void* __p,
size_t __bytes,
size_t __alignment = _S_max_align)
83 __attribute__((__nonnull__))
84 {
return do_deallocate(__p, __bytes, __alignment); }
89 {
return do_is_equal(__other); }
93 do_allocate(
size_t __bytes,
size_t __alignment) = 0;
96 do_deallocate(
void* __p,
size_t __bytes,
size_t __alignment) = 0;
105 {
return &__a == &__b || __a.is_equal(__b); }
107 #if __cpp_impl_three_way_comparison < 201907L
110 operator!=(
const memory_resource& __a,
const memory_resource& __b) noexcept
111 {
return !(__a == __b); }
122 template<
typename _Tp>
127 template<
typename _Up>
128 struct __not_pair {
using type = void; };
130 template<
typename _Up1,
typename _Up2>
131 struct __not_pair<
pair<_Up1, _Up2>> { };
134 using value_type = _Tp;
139 __attribute__((__returns_nonnull__));
144 __attribute__((__nonnull__))
146 { _GLIBCXX_DEBUG_ASSERT(__r); }
150 template<
typename _Up>
152 : _M_resource(__x.resource())
161 __attribute__((__returns_nonnull__))
164 std::__throw_bad_array_new_length();
165 return static_cast<_Tp*
>(_M_resource->allocate(__n *
sizeof(_Tp),
170 deallocate(_Tp* __p,
size_t __n) noexcept
171 __attribute__((__nonnull__))
172 { _M_resource->deallocate(__p, __n *
sizeof(_Tp),
alignof(_Tp)); }
174 #ifdef __glibcxx_polymorphic_allocator
176 allocate_bytes(
size_t __nbytes,
177 size_t __alignment =
alignof(max_align_t))
178 {
return _M_resource->allocate(__nbytes, __alignment); }
181 deallocate_bytes(
void* __p,
size_t __nbytes,
182 size_t __alignment =
alignof(max_align_t))
183 { _M_resource->deallocate(__p, __nbytes, __alignment); }
185 template<
typename _Up>
187 allocate_object(
size_t __n = 1)
190 std::__throw_bad_array_new_length();
191 return static_cast<_Up*
>(allocate_bytes(__n *
sizeof(_Up),
195 template<
typename _Up>
197 deallocate_object(_Up* __p,
size_t __n = 1)
198 { deallocate_bytes(__p, __n *
sizeof(_Up),
alignof(_Up)); }
200 template<
typename _Up,
typename... _CtorArgs>
202 new_object(_CtorArgs&&... __ctor_args)
204 _Up* __p = allocate_object<_Up>();
207 construct(__p, std::forward<_CtorArgs>(__ctor_args)...);
211 deallocate_object(__p);
212 __throw_exception_again;
217 template<
typename _Up>
219 delete_object(_Up* __p)
222 deallocate_object(__p);
226 #if ! __glibcxx_make_obj_using_allocator
227 template<
typename _Tp1,
typename... _Args>
228 __attribute__((__nonnull__))
229 typename __not_pair<_Tp1>::type
230 construct(_Tp1* __p, _Args&&... __args)
236 if constexpr (is_base_of_v<__uses_alloc0, __use_tag>)
237 ::
new(__p) _Tp1(std::forward<_Args>(__args)...);
238 else if constexpr (is_base_of_v<__uses_alloc1_, __use_tag>)
239 ::
new(__p) _Tp1(allocator_arg, *
this,
240 std::forward<_Args>(__args)...);
242 ::new(__p) _Tp1(std::forward<_Args>(__args)..., *
this);
245 template<
typename _Tp1,
typename _Tp2,
246 typename... _Args1,
typename... _Args2>
247 __attribute__((__nonnull__))
260 _S_construct_p(__x_tag, __x_i, __x),
261 _S_construct_p(__y_tag, __y_i, __y));
264 template<
typename _Tp1,
typename _Tp2>
265 __attribute__((__nonnull__))
270 template<
typename _Tp1,
typename _Tp2,
typename _Up,
typename _Vp>
271 __attribute__((__nonnull__))
280 template <
typename _Tp1,
typename _Tp2,
typename _Up,
typename _Vp>
281 __attribute__((__nonnull__))
290 template<
typename _Tp1,
typename _Tp2,
typename _Up,
typename _Vp>
291 __attribute__((__nonnull__))
300 template<
typename _Tp1,
typename... _Args>
301 __attribute__((__nonnull__))
303 construct(_Tp1* __p, _Args&&... __args)
305 std::uninitialized_construct_using_allocator(__p, *
this,
306 std::forward<_Args>(__args)...);
310 template<
typename _Up>
311 __attribute__((__nonnull__))
317 select_on_container_copy_construction()
const noexcept
321 resource()
const noexcept
322 __attribute__((__returns_nonnull__))
323 {
return _M_resource; }
331 {
return *__a.resource() == *__b.resource(); }
333 #if __cpp_impl_three_way_comparison < 201907L
338 {
return !(__a == __b); }
342 #if ! __glibcxx_make_obj_using_allocator
343 using __uses_alloc1_ = __uses_alloc1<polymorphic_allocator>;
344 using __uses_alloc2_ = __uses_alloc2<polymorphic_allocator>;
346 template<
typename _Ind,
typename... _Args>
347 static tuple<_Args&&...>
351 template<
size_t... _Ind,
typename... _Args>
357 allocator_arg, *__ua._M_a, std::get<_Ind>(
std::move(__t))...
361 template<
size_t... _Ind,
typename... _Args>
365 {
return { std::get<_Ind>(
std::move(__t))..., *__ua._M_a }; }
371 template<
typename _Tp1,
typename _Tp2>
376 {
return *__a.resource() == *__b.resource(); }
378 #if __cpp_impl_three_way_comparison < 201907L
379 template<
typename _Tp1,
typename _Tp2>
382 operator!=(
const polymorphic_allocator<_Tp1>& __a,
383 const polymorphic_allocator<_Tp2>& __b) noexcept
384 {
return !(__a == __b); }
389 template<
typename _Alloc>
struct allocator_traits;
397 template<
typename _Tp>
440 template<
typename _Up>
443 template<
typename _Up>
455 {
return __a.allocate(__n); }
470 {
return __a.allocate(__n); }
472 #ifdef __glibcxx_allocate_at_least
483 [[nodiscard]]
static std::allocation_result<pointer, size_type>
485 {
return { __a.allocate(__n), __n }; }
498 { __a.deallocate(__p, __n); }
511 template<
typename _Up,
typename... _Args>
514 { __a.construct(__p, std::forward<_Args>(__args)...); }
523 template<
typename _Up>
524 static _GLIBCXX20_CONSTEXPR
void
538 _GLIBCXX_END_NAMESPACE_VERSION
memory_resource * get_default_resource() noexcept
Get the current default memory resource pointer.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr piecewise_construct_t piecewise_construct
Tag for piecewise construction of std::pair objects.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr tuple< _Elements &&... > forward_as_tuple(_Elements &&... __args) noexcept
Create a tuple of lvalue or rvalue references to the arguments.
ISO C++ entities toplevel namespace is std.
make_index_sequence< sizeof...(_Types)> index_sequence_for
Alias template index_sequence_for.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
Primary class template, tuple.
Uniform interface to all allocator types.
__detected_or_t< value_type *, __pointer, _Alloc > pointer
The allocator's pointer type.
typename _Size< _Alloc, difference_type >::type size_type
The allocator's size type.
_Alloc::value_type value_type
The allocated type.
_Alloc allocator_type
The allocator type.
Class template polymorphic_allocator.
static void construct(allocator_type &__a, _Up *__p, _Args &&... __args)
Construct an object of type _Up
std::ptrdiff_t difference_type
The allocator's difference type.
static void deallocate(allocator_type &__a, pointer __p, size_type __n)
Deallocate memory.
_Tp value_type
The allocated type.
static constexpr void destroy(allocator_type &, _Up *__p) noexcept(is_nothrow_destructible< _Up >::value)
Destroy an object of type _Up
static constexpr size_type max_size(const allocator_type &) noexcept
The maximum supported allocation size.
static std::allocation_result< pointer, size_type > allocate_at_least(allocator_type &__a, size_type __n)
Allocate memory.
static pointer allocate(allocator_type &__a, size_type __n)
Allocate memory.
false_type propagate_on_container_swap
_Tp * pointer
The allocator's pointer type.
const _Tp * const_pointer
The allocator's const pointer type.
false_type propagate_on_container_move_assignment
static pointer allocate(allocator_type &__a, size_type __n, const_void_pointer)
Allocate memory.
const void * const_void_pointer
The allocator's const void pointer type.
false_type propagate_on_container_copy_assignment
static allocator_type select_on_container_copy_construction(const allocator_type &) noexcept
void * void_pointer
The allocator's void pointer type.
false_type is_always_equal
Whether all instances of the allocator type compare equal.
std::size_t size_type
The allocator's size type.
Struct holding two objects (or references) of arbitrary type.
_T1 first
The first member.
_T2 second
The second member.
Tag type for piecewise construction of std::pair objects.
Class template integer_sequence.