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
52 namespace std _GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
65 static constexpr
size_t _S_max_align =
alignof(max_align_t);
76 allocate(
size_t __bytes,
size_t __alignment = _S_max_align)
77 __attribute__((__returns_nonnull__,__alloc_size__(2),__alloc_align__(3)))
78 { return ::operator
new(__bytes, do_allocate(__bytes, __alignment)); }
81 deallocate(
void* __p,
size_t __bytes,
size_t __alignment = _S_max_align)
82 __attribute__((__nonnull__))
83 {
return do_deallocate(__p, __bytes, __alignment); }
88 {
return do_is_equal(__other); }
92 do_allocate(
size_t __bytes,
size_t __alignment) = 0;
95 do_deallocate(
void* __p,
size_t __bytes,
size_t __alignment) = 0;
104 {
return &__a == &__b || __a.is_equal(__b); }
106 #if __cpp_impl_three_way_comparison < 201907L
109 operator!=(
const memory_resource& __a,
const memory_resource& __b) noexcept
110 {
return !(__a == __b); }
121 template<
typename _Tp>
126 template<
typename _Up>
127 struct __not_pair {
using type = void; };
129 template<
typename _Up1,
typename _Up2>
130 struct __not_pair<
pair<_Up1, _Up2>> { };
133 using value_type = _Tp;
138 __attribute__((__returns_nonnull__));
143 __attribute__((__nonnull__))
145 { _GLIBCXX_DEBUG_ASSERT(__r); }
149 template<
typename _Up>
151 : _M_resource(__x.resource())
160 __attribute__((__returns_nonnull__))
163 std::__throw_bad_array_new_length();
164 return static_cast<_Tp*
>(_M_resource->allocate(__n *
sizeof(_Tp),
169 deallocate(_Tp* __p,
size_t __n) noexcept
170 __attribute__((__nonnull__))
171 { _M_resource->deallocate(__p, __n *
sizeof(_Tp),
alignof(_Tp)); }
173 #ifdef __glibcxx_polymorphic_allocator
175 allocate_bytes(
size_t __nbytes,
176 size_t __alignment =
alignof(max_align_t))
177 {
return _M_resource->allocate(__nbytes, __alignment); }
180 deallocate_bytes(
void* __p,
size_t __nbytes,
181 size_t __alignment =
alignof(max_align_t))
182 { _M_resource->deallocate(__p, __nbytes, __alignment); }
184 template<
typename _Up>
186 allocate_object(
size_t __n = 1)
189 std::__throw_bad_array_new_length();
190 return static_cast<_Up*
>(allocate_bytes(__n *
sizeof(_Up),
194 template<
typename _Up>
196 deallocate_object(_Up* __p,
size_t __n = 1)
197 { deallocate_bytes(__p, __n *
sizeof(_Up),
alignof(_Up)); }
199 template<
typename _Up,
typename... _CtorArgs>
201 new_object(_CtorArgs&&... __ctor_args)
203 _Up* __p = allocate_object<_Up>();
206 construct(__p, std::forward<_CtorArgs>(__ctor_args)...);
210 deallocate_object(__p);
211 __throw_exception_again;
216 template<
typename _Up>
218 delete_object(_Up* __p)
221 deallocate_object(__p);
225 #if ! __glibcxx_make_obj_using_allocator
226 template<
typename _Tp1,
typename... _Args>
227 __attribute__((__nonnull__))
228 typename __not_pair<_Tp1>::type
229 construct(_Tp1* __p, _Args&&... __args)
235 if constexpr (is_base_of_v<__uses_alloc0, __use_tag>)
236 ::
new(__p) _Tp1(std::forward<_Args>(__args)...);
237 else if constexpr (is_base_of_v<__uses_alloc1_, __use_tag>)
238 ::
new(__p) _Tp1(allocator_arg, *
this,
239 std::forward<_Args>(__args)...);
241 ::new(__p) _Tp1(std::forward<_Args>(__args)..., *
this);
244 template<
typename _Tp1,
typename _Tp2,
245 typename... _Args1,
typename... _Args2>
246 __attribute__((__nonnull__))
259 _S_construct_p(__x_tag, __x_i, __x),
260 _S_construct_p(__y_tag, __y_i, __y));
263 template<
typename _Tp1,
typename _Tp2>
264 __attribute__((__nonnull__))
269 template<
typename _Tp1,
typename _Tp2,
typename _Up,
typename _Vp>
270 __attribute__((__nonnull__))
279 template <
typename _Tp1,
typename _Tp2,
typename _Up,
typename _Vp>
280 __attribute__((__nonnull__))
289 template<
typename _Tp1,
typename _Tp2,
typename _Up,
typename _Vp>
290 __attribute__((__nonnull__))
299 template<
typename _Tp1,
typename... _Args>
300 __attribute__((__nonnull__))
302 construct(_Tp1* __p, _Args&&... __args)
304 std::uninitialized_construct_using_allocator(__p, *
this,
305 std::forward<_Args>(__args)...);
309 template<
typename _Up>
310 __attribute__((__nonnull__))
316 select_on_container_copy_construction()
const noexcept
320 resource()
const noexcept
321 __attribute__((__returns_nonnull__))
322 {
return _M_resource; }
330 {
return *__a.resource() == *__b.resource(); }
332 #if __cpp_impl_three_way_comparison < 201907L
337 {
return !(__a == __b); }
341 #if ! __glibcxx_make_obj_using_allocator
342 using __uses_alloc1_ = __uses_alloc1<polymorphic_allocator>;
343 using __uses_alloc2_ = __uses_alloc2<polymorphic_allocator>;
345 template<
typename _Ind,
typename... _Args>
346 static tuple<_Args&&...>
350 template<
size_t... _Ind,
typename... _Args>
356 allocator_arg, *__ua._M_a, std::get<_Ind>(
std::move(__t))...
360 template<
size_t... _Ind,
typename... _Args>
364 {
return { std::get<_Ind>(
std::move(__t))..., *__ua._M_a }; }
370 template<
typename _Tp1,
typename _Tp2>
375 {
return *__a.resource() == *__b.resource(); }
377 #if __cpp_impl_three_way_comparison < 201907L
378 template<
typename _Tp1,
typename _Tp2>
381 operator!=(
const polymorphic_allocator<_Tp1>& __a,
382 const polymorphic_allocator<_Tp2>& __b) noexcept
383 {
return !(__a == __b); }
388 template<
typename _Alloc>
struct allocator_traits;
396 template<
typename _Tp>
439 template<
typename _Up>
442 template<
typename _Up>
454 {
return __a.allocate(__n); }
469 {
return __a.allocate(__n); }
481 { __a.deallocate(__p, __n); }
494 template<
typename _Up,
typename... _Args>
497 { __a.construct(__p, std::forward<_Args>(__args)...); }
506 template<
typename _Up>
507 static _GLIBCXX20_CONSTEXPR
void
521 _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 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 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.