30#ifndef _ALLOC_TRAITS_H
31#define _ALLOC_TRAITS_H 1
33#if __cplusplus >= 201103L
39#define __cpp_lib_allocator_traits_is_always_equal 201411
41namespace std _GLIBCXX_VISIBILITY(default)
43_GLIBCXX_BEGIN_NAMESPACE_VERSION
45 struct __allocator_traits_base
47 template<
typename _Tp,
typename _Up,
typename =
void>
48 struct __rebind : __replace_first_arg<_Tp, _Up> { };
50 template<
typename _Tp,
typename _Up>
51 struct __rebind<_Tp, _Up,
52 __void_t<typename _Tp::template rebind<_Up>::other>>
53 {
using type =
typename _Tp::template rebind<_Up>::other; };
56 template<
typename _Tp>
57 using __pointer =
typename _Tp::pointer;
58 template<
typename _Tp>
59 using __c_pointer =
typename _Tp::const_pointer;
60 template<
typename _Tp>
61 using __v_pointer =
typename _Tp::void_pointer;
62 template<
typename _Tp>
63 using __cv_pointer =
typename _Tp::const_void_pointer;
64 template<
typename _Tp>
65 using __pocca =
typename _Tp::propagate_on_container_copy_assignment;
66 template<
typename _Tp>
67 using __pocma =
typename _Tp::propagate_on_container_move_assignment;
68 template<
typename _Tp>
69 using __pocs =
typename _Tp::propagate_on_container_swap;
70 template<
typename _Tp>
71 using __equal =
typename _Tp::is_always_equal;
74 template<
typename _Alloc,
typename _Up>
76 =
typename __allocator_traits_base::template __rebind<_Alloc, _Up>::type;
82 template<
typename _Alloc>
95 using pointer = __detected_or_t<value_type*, __pointer, _Alloc>;
99 template<
template<
typename>
class _Func,
typename _Tp,
typename =
void>
105 template<
template<
typename>
class _Func,
typename _Tp>
106 struct _Ptr<_Func, _Tp, __void_t<_Func<_Alloc>>>
108 using type = _Func<_Alloc>;
112 template<
typename _A2,
typename _PtrT,
typename =
void>
116 template<
typename _A2,
typename _PtrT>
118 {
using type =
typename _A2::difference_type; };
121 template<
typename _A2,
typename _DiffT,
typename =
void>
122 struct _Size : make_unsigned<_DiffT> { };
124 template<
typename _A2,
typename _DiffT>
125 struct _Size<_A2, _DiffT, __void_t<typename _A2::
size_type>>
126 {
using type =
typename _A2::size_type; };
167 using size_type =
typename _Size<_Alloc, difference_type>::type;
176 = __detected_or_t<false_type, __pocca, _Alloc>;
185 = __detected_or_t<false_type, __pocma, _Alloc>;
194 = __detected_or_t<false_type, __pocs, _Alloc>;
203 = __detected_or_t<typename is_empty<_Alloc>::type, __equal, _Alloc>;
205 template<
typename _Tp>
206 using rebind_alloc = __alloc_rebind<_Alloc, _Tp>;
207 template<
typename _Tp>
211 template<
typename _Alloc2>
214 ->
decltype(__a.allocate(__n, __hint))
215 {
return __a.
allocate(__n, __hint); }
217 template<
typename _Alloc2>
220 {
return __a.allocate(__n); }
222 template<
typename _Tp,
typename... _Args>
223 struct __construct_helper
225 template<
typename _Alloc2,
226 typename =
decltype(std::declval<_Alloc2*>()->construct(
227 std::declval<_Tp*>(), std::declval<_Args>()...))>
233 using type =
decltype(__test<_Alloc>(0));
236 template<
typename _Tp,
typename... _Args>
237 using __has_construct
238 =
typename __construct_helper<_Tp, _Args...>::type;
240 template<
typename _Tp,
typename... _Args>
241 static _Require<__has_construct<_Tp, _Args...>>
242 _S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
243 noexcept(
noexcept(__a.construct(__p, std::forward<_Args>(__args)...)))
244 { __a.construct(__p, std::forward<_Args>(__args)...); }
246 template<
typename _Tp,
typename... _Args>
248 _Require<__and_<__not_<__has_construct<_Tp, _Args...>>,
249 is_constructible<_Tp, _Args...>>>
250 _S_construct(_Alloc&, _Tp* __p, _Args&&... __args)
252 { ::new((
void*)__p) _Tp(std::forward<_Args>(__args)...); }
254 template<
typename _Alloc2,
typename _Tp>
256 _S_destroy(_Alloc2& __a, _Tp* __p,
int)
257 noexcept(
noexcept(__a.destroy(__p)))
258 ->
decltype(__a.destroy(__p))
259 { __a.destroy(__p); }
261 template<
typename _Alloc2,
typename _Tp>
263 _S_destroy(_Alloc2&, _Tp* __p, ...)
264 noexcept(
std::is_nothrow_destructible<_Tp>::value)
267 template<
typename _Alloc2>
269 _S_max_size(_Alloc2& __a,
int)
270 ->
decltype(__a.max_size())
271 {
return __a.max_size(); }
273 template<
typename _Alloc2>
275 _S_max_size(_Alloc2&, ...)
279 return __gnu_cxx::__numeric_traits<size_type>::__max
283 template<
typename _Alloc2>
285 _S_select(_Alloc2& __a,
int)
286 ->
decltype(__a.select_on_container_copy_construction())
287 {
return __a.select_on_container_copy_construction(); }
289 template<
typename _Alloc2>
291 _S_select(_Alloc2& __a, ...)
303 _GLIBCXX_NODISCARD
static pointer
305 {
return __a.allocate(__n); }
318 _GLIBCXX_NODISCARD
static pointer
320 {
return _S_allocate(__a, __n, __hint, 0); }
332 { __a.deallocate(__p, __n); }
345 template<
typename _Tp,
typename... _Args>
346 static auto construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
347 noexcept(
noexcept(_S_construct(__a, __p,
348 std::forward<_Args>(__args)...)))
349 ->
decltype(_S_construct(__a, __p, std::forward<_Args>(__args)...))
350 { _S_construct(__a, __p, std::forward<_Args>(__args)...); }
360 template<
typename _Tp>
362 noexcept(
noexcept(_S_destroy(__a, __p, 0)))
363 { _S_destroy(__a, __p, 0); }
374 {
return _S_max_size(__a, 0); }
386 {
return _S_select(__rhs, 0); }
390 template<
typename _Tp>
428 template<
typename _Up>
431 template<
typename _Up>
441 _GLIBCXX_NODISCARD
static pointer
443 {
return __a.allocate(__n); }
455 _GLIBCXX_NODISCARD
static pointer
457 {
return __a.allocate(__n, __hint); }
469 { __a.deallocate(__p, __n); }
479 template<
typename _Up,
typename... _Args>
483 { __a.construct(__p, std::forward<_Args>(__args)...); }
492 template<
typename _Up>
495 noexcept(
noexcept(__a.destroy(__p)))
496 { __a.destroy(__p); }
505 {
return __a.max_size(); }
518 template<
typename _Alloc>
520 __do_alloc_on_copy(_Alloc& __one,
const _Alloc& __two,
true_type)
523 template<
typename _Alloc>
525 __do_alloc_on_copy(_Alloc&,
const _Alloc&,
false_type)
528 template<
typename _Alloc>
529 inline void __alloc_on_copy(_Alloc& __one,
const _Alloc& __two)
531 typedef allocator_traits<_Alloc> __traits;
532 typedef typename __traits::propagate_on_container_copy_assignment __pocca;
533 __do_alloc_on_copy(__one, __two, __pocca());
536 template<
typename _Alloc>
537 inline _Alloc __alloc_on_copy(
const _Alloc& __a)
539 typedef allocator_traits<_Alloc> __traits;
540 return __traits::select_on_container_copy_construction(__a);
543 template<
typename _Alloc>
544 inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two,
true_type)
545 { __one = std::move(__two); }
547 template<
typename _Alloc>
548 inline void __do_alloc_on_move(_Alloc&, _Alloc&,
false_type)
551 template<
typename _Alloc>
552 inline void __alloc_on_move(_Alloc& __one, _Alloc& __two)
554 typedef allocator_traits<_Alloc> __traits;
555 typedef typename __traits::propagate_on_container_move_assignment __pocma;
556 __do_alloc_on_move(__one, __two, __pocma());
559 template<
typename _Alloc>
560 inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two,
true_type)
566 template<
typename _Alloc>
567 inline void __do_alloc_on_swap(_Alloc&, _Alloc&,
false_type)
570 template<
typename _Alloc>
571 inline void __alloc_on_swap(_Alloc& __one, _Alloc& __two)
573 typedef allocator_traits<_Alloc> __traits;
574 typedef typename __traits::propagate_on_container_swap __pocs;
575 __do_alloc_on_swap(__one, __two, __pocs());
578 template<
typename _Alloc,
typename _Tp,
579 typename _ValueT = __remove_cvref_t<typename _Alloc::value_type>,
581 struct __is_alloc_insertable_impl
585 template<
typename _Alloc,
typename _Tp,
typename _ValueT>
586 struct __is_alloc_insertable_impl<_Alloc, _Tp, _ValueT,
587 __void_t<decltype(allocator_traits<_Alloc>::construct(
588 std::declval<_Alloc&>(), std::declval<_ValueT*>(),
589 std::declval<_Tp>()))>>
596 template<
typename _Alloc>
597 struct __is_copy_insertable
598 : __is_alloc_insertable_impl<_Alloc,
599 typename _Alloc::value_type const&>::type
603 template<
typename _Tp>
604 struct __is_copy_insertable<allocator<_Tp>>
605 : is_copy_constructible<_Tp>
611 template<
typename _Alloc>
612 struct __is_move_insertable
613 : __is_alloc_insertable_impl<_Alloc, typename _Alloc::value_type>::type
617 template<
typename _Tp>
618 struct __is_move_insertable<allocator<_Tp>>
619 : is_move_constructible<_Tp>
623 template<
typename _Alloc,
typename =
void>
626 template<
typename _Alloc>
627 struct __is_allocator<_Alloc,
628 __void_t<typename _Alloc::value_type,
629 decltype(std::declval<_Alloc&>().allocate(size_t{}))>>
632 template<
typename _Alloc>
633 using _RequireAllocator
634 =
typename enable_if<__is_allocator<_Alloc>::value, _Alloc>::type;
636 template<
typename _Alloc>
637 using _RequireNotAllocator
638 =
typename enable_if<!__is_allocator<_Alloc>::value, _Alloc>::type;
640_GLIBCXX_END_NAMESPACE_VERSION
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.
ISO C++ entities toplevel namespace is std.
Uniform interface to all allocator types.
static _GLIBCXX_NODISCARD pointer allocate(_Alloc &__a, size_type __n, const_void_pointer __hint)
Allocate memory.
__detected_or_t< false_type, __pocma, _Alloc > propagate_on_container_move_assignment
How the allocator is propagated on move assignment.
typename _Ptr< __v_pointer, void >::type void_pointer
The allocator's void pointer type.
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
static void destroy(_Alloc &__a, _Tp *__p) noexcept(noexcept(_S_destroy(__a, __p, 0)))
Destroy an object of type _Tp.
__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.
typename _Ptr< __cv_pointer, const void >::type const_void_pointer
The allocator's const void pointer type.
typename _Diff< _Alloc, pointer >::type difference_type
The allocator's difference type.
typename _Ptr< __c_pointer, const value_type >::type const_pointer
The allocator's const pointer type.
_Alloc::value_type value_type
The allocated type.
static _Alloc select_on_container_copy_construction(const _Alloc &__rhs)
Obtain an allocator to use when copying a container.
__detected_or_t< false_type, __pocca, _Alloc > propagate_on_container_copy_assignment
How the allocator is propagated on copy assignment.
static auto construct(_Alloc &__a, _Tp *__p, _Args &&... __args) noexcept(noexcept(_S_construct(__a, __p, std::forward< _Args >(__args)...))) -> decltype(_S_construct(__a, __p, std::forward< _Args >(__args)...))
Construct an object of type `_Tp`.
__detected_or_t< false_type, __pocs, _Alloc > propagate_on_container_swap
How the allocator is propagated on swap.
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
__detected_or_t< typename is_empty< _Alloc >::type, __equal, _Alloc > is_always_equal
Whether all instances of the allocator type compare equal.
_Alloc allocator_type
The allocator type.
static _GLIBCXX_NODISCARD pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
static void destroy(allocator_type &__a, _Up *__p) noexcept(noexcept(__a.destroy(__p)))
Destroy an object of type _Up.
static void deallocate(allocator_type &__a, pointer __p, size_type __n)
Deallocate memory.
allocator< _Tp > allocator_type
The allocator type.
static _GLIBCXX_NODISCARD pointer allocate(allocator_type &__a, size_type __n, const_void_pointer __hint)
Allocate memory.
void * void_pointer
The allocator's void pointer type.
static _GLIBCXX_NODISCARD pointer allocate(allocator_type &__a, size_type __n)
Allocate memory.
_Tp * pointer
The allocator's pointer type.
_Tp value_type
The allocated type.
static size_type max_size(const allocator_type &__a) noexcept
The maximum supported allocation size.
std::ptrdiff_t difference_type
The allocator's difference type.
const _Tp * const_pointer
The allocator's const pointer type.
const void * const_void_pointer
The allocator's const void pointer type.
static allocator_type select_on_container_copy_construction(const allocator_type &__rhs)
Obtain an allocator to use when copying a container.
static void construct(allocator_type &__a, _Up *__p, _Args &&... __args) noexcept(std::is_nothrow_constructible< _Up, _Args... >::value)
Construct an object of type _Up.
std::size_t size_type
The allocator's size type.
The standard allocator, as per [20.4].
Uniform interface to all pointer-like types.
__detected_or_t< ptrdiff_t, __difference_type, _Ptr > difference_type
The type used to represent the difference between two pointers.