29 #ifndef _SCOPED_ALLOCATOR 30 #define _SCOPED_ALLOCATOR 1 32 #pragma GCC system_header 34 #if __cplusplus < 201103L 43 namespace std _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 template<
typename _Alloc>
53 using __outer_allocator_t
54 = decltype(std::declval<_Alloc>().outer_allocator());
56 template<
typename _Alloc,
typename =
void>
57 struct __outermost_type
60 static type& _S_outermost(_Alloc& __a) {
return __a; }
63 template<
typename _Alloc>
64 struct __outermost_type<_Alloc, __void_t<__outer_allocator_t<_Alloc>>>
66 typename remove_reference<__outer_allocator_t<_Alloc>>::type
69 using __base = __outermost_type<
70 typename remove_reference<__outer_allocator_t<_Alloc>>::type
73 static typename __base::type&
74 _S_outermost(_Alloc& __a)
75 {
return __base::_S_outermost(__a.outer_allocator()); }
78 template<
typename _Alloc>
79 inline typename __outermost_type<_Alloc>::type&
80 __outermost(_Alloc& __a)
81 {
return __outermost_type<_Alloc>::_S_outermost(__a); }
83 template<
typename _OuterAlloc,
typename... _InnerAllocs>
87 struct __inner_type_impl;
89 template<
typename _Outer>
90 struct __inner_type_impl<_Outer>
94 __inner_type_impl() =
default;
95 __inner_type_impl(
const __inner_type_impl&) =
default;
96 __inner_type_impl(__inner_type_impl&&) =
default;
97 __inner_type_impl& operator=(
const __inner_type_impl&) =
default;
98 __inner_type_impl& operator=(__inner_type_impl&&) =
default;
100 template<
typename _Alloc>
101 __inner_type_impl(
const __inner_type_impl<_Alloc>& __other)
104 template<
typename _Alloc>
105 __inner_type_impl(__inner_type_impl<_Alloc>&& __other)
109 _M_get(__type* __p) noexcept {
return *__p; }
112 _M_get(
const __type* __p)
const noexcept {
return *__p; }
115 _M_tie() const noexcept {
return tuple<>(); }
118 operator==(
const __inner_type_impl&)
const noexcept
122 template<
typename _Outer,
typename _InnerHead,
typename... _InnerTail>
123 struct __inner_type_impl<_Outer, _InnerHead, _InnerTail...>
127 __inner_type_impl() =
default;
128 __inner_type_impl(
const __inner_type_impl&) =
default;
129 __inner_type_impl(__inner_type_impl&&) =
default;
130 __inner_type_impl& operator=(
const __inner_type_impl&) =
default;
131 __inner_type_impl& operator=(__inner_type_impl&&) =
default;
133 template<
typename... _Allocs>
134 __inner_type_impl(
const __inner_type_impl<_Allocs...>& __other)
135 : _M_inner(__other._M_inner) { }
137 template<
typename... _Allocs>
138 __inner_type_impl(__inner_type_impl<_Allocs...>&& __other)
139 : _M_inner(
std::move(__other._M_inner)) { }
141 template<
typename... _Args>
143 __inner_type_impl(_Args&&... __args)
144 : _M_inner(
std::
forward<_Args>(__args)...) { }
147 _M_get(
void*) noexcept {
return _M_inner; }
150 _M_get(
const void*)
const noexcept {
return _M_inner; }
152 tuple<
const _InnerHead&,
const _InnerTail&...>
153 _M_tie() const noexcept
154 {
return _M_inner._M_tie(); }
157 operator==(
const __inner_type_impl& __other)
const noexcept
158 {
return _M_inner == __other._M_inner; }
161 template<
typename...>
friend class __inner_type_impl;
168 template<
typename _OuterAlloc,
typename... _InnerAllocs>
174 typedef __inner_type_impl<_OuterAlloc, _InnerAllocs...> __inner_type;
175 __inner_type _M_inner;
177 template<
typename _Outer,
typename... _Inner>
180 template<
typename...>
181 friend class __inner_type_impl;
183 tuple<
const _OuterAlloc&,
const _InnerAllocs&...>
184 _M_tie() const noexcept
187 template<
typename _Alloc>
191 #if __cplusplus <= 201703 192 template<
typename _Tp,
typename... _Args>
194 _M_construct(__uses_alloc0, _Tp* __p, _Args&&... __args)
197 _O_traits::construct(__outermost(*
this), __p,
198 std::forward<_Args>(__args)...);
201 typedef __uses_alloc1<typename __inner_type::__type> __uses_alloc1_;
202 typedef __uses_alloc2<typename __inner_type::__type> __uses_alloc2_;
204 template<
typename _Tp,
typename... _Args>
206 _M_construct(__uses_alloc1_, _Tp* __p, _Args&&... __args)
209 _O_traits::construct(__outermost(*
this), __p,
210 allocator_arg, inner_allocator(),
211 std::forward<_Args>(__args)...);
214 template<
typename _Tp,
typename... _Args>
216 _M_construct(__uses_alloc2_, _Tp* __p, _Args&&... __args)
219 _O_traits::construct(__outermost(*
this), __p,
220 std::forward<_Args>(__args)...,
225 template<
typename _Alloc>
227 _S_select_on_copy(
const _Alloc& __a)
230 return __a_traits::select_on_container_copy_construction(__a);
233 template<std::size_t... _Indices>
235 const _InnerAllocs&...> __refs,
236 _Index_tuple<_Indices...>)
237 : _OuterAlloc(_S_select_on_copy(
std::get<0>(__refs))),
238 _M_inner(_S_select_on_copy(
std::get<_Indices+1>(__refs))...)
242 template<
typename _Alloc>
243 using _Constructible =
typename enable_if<
249 template<
typename _Tp>
250 struct __not_pair {
using type = void; };
252 template<
typename _Tp,
typename _Up>
253 struct __not_pair<
pair<_Tp, _Up>> { };
256 typedef _OuterAlloc outer_allocator_type;
257 typedef typename __inner_type::__type inner_allocator_type;
267 typedef typename __or_<
270 propagate_on_container_copy_assignment...>::type
271 propagate_on_container_copy_assignment;
273 typedef typename __or_<
276 propagate_on_container_move_assignment...>::type
277 propagate_on_container_move_assignment;
279 typedef typename __or_<
282 propagate_on_container_swap...>::type
283 propagate_on_container_swap;
285 typedef typename __and_<
294 typename __traits::template rebind_alloc<_Tp>,
295 _InnerAllocs...> other;
300 template<
typename _Outer2,
typename = _Constructible<_Outer2>>
302 const _InnerAllocs&... __inner)
303 : _OuterAlloc(
std::
forward<_Outer2>(__outer)),
308 : _OuterAlloc(__other.outer_allocator()),
309 _M_inner(__other._M_inner)
313 : _OuterAlloc(
std::move(__other.outer_allocator())),
314 _M_inner(
std::move(__other._M_inner))
317 template<
typename _Outer2,
typename = _Constructible<const _Outer2&>>
320 : _OuterAlloc(__other.outer_allocator()),
321 _M_inner(__other._M_inner)
324 template<
typename _Outer2,
typename = _Constructible<_Outer2>>
327 : _OuterAlloc(
std::move(__other.outer_allocator())),
328 _M_inner(
std::move(__other._M_inner))
337 inner_allocator_type& inner_allocator() noexcept
338 {
return _M_inner._M_get(
this); }
340 const inner_allocator_type& inner_allocator() const noexcept
341 {
return _M_inner._M_get(
this); }
343 outer_allocator_type& outer_allocator() noexcept
344 {
return static_cast<_OuterAlloc&
>(*this); }
346 const outer_allocator_type& outer_allocator() const noexcept
347 {
return static_cast<const _OuterAlloc&
>(*this); }
349 _GLIBCXX_NODISCARD pointer allocate(size_type __n)
350 {
return __traits::allocate(outer_allocator(), __n); }
352 _GLIBCXX_NODISCARD pointer allocate(size_type __n, const_void_pointer __hint)
353 {
return __traits::allocate(outer_allocator(), __n, __hint); }
355 void deallocate(pointer __p, size_type __n)
356 {
return __traits::deallocate(outer_allocator(), __p, __n); }
358 size_type max_size()
const 359 {
return __traits::max_size(outer_allocator()); }
361 #if __cplusplus <= 201703 362 template<
typename _Tp,
typename... _Args>
363 typename __not_pair<_Tp>::type
364 construct(_Tp* __p, _Args&&... __args)
366 auto& __inner = inner_allocator();
368 = std::__use_alloc<_Tp, inner_allocator_type, _Args...>(__inner);
369 _M_construct(__use_tag, __p, std::forward<_Args>(__args)...);
372 template<
typename _T1,
typename _T2,
typename... _Args1,
380 auto& __inner = inner_allocator();
382 = std::__use_alloc<_T1, inner_allocator_type, _Args1...>(__inner);
384 = std::__use_alloc<_T2, inner_allocator_type, _Args2...>(__inner);
385 typename _Build_index_tuple<
sizeof...(_Args1)>::__type __x_indices;
386 typename _Build_index_tuple<
sizeof...(_Args2)>::__type __y_indices;
389 _M_construct_p(__x_use_tag, __x_indices, __x),
390 _M_construct_p(__y_use_tag, __y_indices, __y));
393 template<
typename _T1,
typename _T2>
398 template<
typename _T1,
typename _T2,
typename _Up,
typename _Vp>
407 template<
typename _T1,
typename _T2,
typename _Up,
typename _Vp>
416 template<
typename _T1,
typename _T2,
typename _Up,
typename _Vp>
425 template<
typename _Tp,
typename... _Args>
426 __attribute__((__nonnull__))
428 construct(_Tp* __p, _Args&&... __args)
431 std::apply([__p,
this](
auto&&... __newargs) {
432 _O_traits::construct(__outermost(*
this), __p,
435 uses_allocator_construction_args<_Tp>(inner_allocator(),
436 std::forward<_Args>(__args)...));
440 template<
typename _Tp>
441 void destroy(_Tp* __p)
444 _O_traits::destroy(__outermost(*
this), __p);
448 select_on_container_copy_construction()
const 450 typedef typename _Build_index_tuple<
sizeof...(_InnerAllocs)>::__type
455 template <
typename _OutA1,
typename _OutA2,
typename... _InA>
461 #if __cplusplus <= 201703L 462 template<
typename _Ind,
typename... _Args>
465 {
return std::move(__t); }
467 template<
size_t... _Ind,
typename... _Args>
469 _M_construct_p(__uses_alloc1_, _Index_tuple<_Ind...>,
472 return { allocator_arg, inner_allocator(),
473 std::get<_Ind>(std::move(__t))...
477 template<
size_t... _Ind,
typename... _Args>
478 tuple<_Args&&..., inner_allocator_type&>
479 _M_construct_p(__uses_alloc2_, _Index_tuple<_Ind...>,
482 return { std::get<_Ind>(std::move(__t))..., inner_allocator() };
487 template <
typename _OutA1,
typename _OutA2,
typename... _InA>
492 return __a.outer_allocator() == __b.outer_allocator()
493 && __a._M_inner == __b._M_inner;
496 template <
typename _OutA1,
typename _OutA2,
typename... _InA>
500 {
return !(__a == __b); }
504 _GLIBCXX_END_NAMESPACE_VERSION
509 #endif // _SCOPED_ALLOCATOR _GLIBCXX17_INLINE constexpr piecewise_construct_t piecewise_construct
piecewise_construct
constexpr tuple< _Elements &&... > forward_as_tuple(_Elements &&... __args) noexcept
std::forward_as_tuple
_Alloc::value_type value_type
The allocated type.
__detected_or_t< false_type, __pocca, _Alloc > propagate_on_container_copy_assignment
How the allocator is propagated on copy assignment.
_T1 first
second_type is the second bound type
__detected_or_t< false_type, __pocs, _Alloc > propagate_on_container_swap
How the allocator is propagated on swap.
Primary class template, tuple.
ISO C++ entities toplevel namespace is std.
_T2 second
first is a copy of the first object
constexpr tuple< _Elements &... > tie(_Elements &... __args) noexcept
tie
Struct holding two objects of arbitrary type.
Define a member typedef type only if a boolean constant is true.
constexpr auto tuple_cat(_Tpls &&... __tpls) -> typename __tuple_cat_result< _Tpls... >::__type
tuple_cat
Uniform interface to all allocator types.
__detected_or_t< typename is_empty< _Alloc >::type, __equal, _Alloc > is_always_equal
Whether all instances of the allocator type compare equal.
typename _Diff< _Alloc, pointer >::type difference_type
The allocator's difference type.
typename _Ptr< __cv_pointer, const void >::type const_void_pointer
The allocator's const void pointer type.
typename _Ptr< __v_pointer, void >::type void_pointer
The allocator's void pointer type.
typename _Ptr< __c_pointer, const value_type >::type const_pointer
The allocator's const pointer type.
_Iterator __base(_Iterator __it)
__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.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
__detected_or_t< false_type, __pocma, _Alloc > propagate_on_container_move_assignment
How the allocator is propagated on move assignment.