65 static constexpr size_t _S_max_align =
alignof(max_align_t);
68 memory_resource() =
default;
69 memory_resource(
const memory_resource&) =
default;
70 virtual ~memory_resource();
72 memory_resource& operator=(
const memory_resource&) =
default;
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); }
87 is_equal(
const memory_resource& __other)
const noexcept
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;
98 do_is_equal(
const memory_resource& __other)
const noexcept = 0;
122 class polymorphic_allocator
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;
135 polymorphic_allocator()
noexcept
138 __attribute__((__returns_nonnull__));
143 __attribute__((__nonnull__))
145 { _GLIBCXX_DEBUG_ASSERT(__r); }
147 polymorphic_allocator(
const polymorphic_allocator& __other) =
default;
149 template<
typename _Up>
150 polymorphic_allocator(
const polymorphic_allocator<_Up>& __x) noexcept
151 : _M_resource(__x.resource())
154 polymorphic_allocator&
155 operator=(
const polymorphic_allocator&) =
delete;
160 __attribute__((__returns_nonnull__))
162 if ((__gnu_cxx::__int_traits<size_t>::__max /
sizeof(_Tp)) < __n)
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)
188 if ((__gnu_cxx::__int_traits<size_t>::__max /
sizeof(_Up)) < __n)
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>();
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)
234 = std::__uses_alloc_t<_Tp1, polymorphic_allocator, _Args...>;
235 if constexpr (is_base_of_v<__uses_alloc0, __use_tag>)
237 else if constexpr (is_base_of_v<__uses_alloc1_, __use_tag>)
238 ::new(__p) _Tp1(allocator_arg, *
this,
244 template<
typename _Tp1,
typename _Tp2,
245 typename... _Args1,
typename... _Args2>
246 __attribute__((__nonnull__))
252 __use_alloc<_Tp1, polymorphic_allocator, _Args1...>(*this);
254 __use_alloc<_Tp2, polymorphic_allocator, _Args2...>(*this);
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,
309 template<
typename _Up>
310 __attribute__((__nonnull__))
315 polymorphic_allocator
316 select_on_container_copy_construction()
const noexcept
317 {
return polymorphic_allocator(); }
320 resource()
const noexcept
321 __attribute__((__returns_nonnull__))
322 {
return _M_resource; }
328 operator==(
const polymorphic_allocator& __a,
329 const polymorphic_allocator& __b)
noexcept
330 {
return *__a.resource() == *__b.resource(); }
332#if __cpp_impl_three_way_comparison < 201907L
335 operator!=(
const polymorphic_allocator& __a,
336 const polymorphic_allocator& __b)
noexcept
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>
351 static tuple<allocator_arg_t, polymorphic_allocator, _Args&&...>
356 allocator_arg, *__ua._M_a, std::get<_Ind>(
std::move(__t))...
360 template<
size_t... _Ind,
typename... _Args>
361 static tuple<_Args&&..., polymorphic_allocator>
364 {
return { std::get<_Ind>(
std::move(__t))..., *__ua._M_a }; }