30#ifndef _ALLOC_TRAITS_H
31#define _ALLOC_TRAITS_H 1
35#if __cplusplus >= 201103L
46namespace std _GLIBCXX_VISIBILITY(default)
48_GLIBCXX_BEGIN_NAMESPACE_VERSION
50#if __cplusplus >= 201103L
52#pragma GCC diagnostic push
53#pragma GCC diagnostic ignored "-Wc++14-extensions"
54#pragma GCC diagnostic ignored "-Wc++17-extensions"
57 struct __allocator_traits_base
59 template<
typename _Tp,
typename _Up,
typename =
void>
60 struct __rebind : __replace_first_arg<_Tp, _Up>
62 static_assert(is_same<
63 typename __replace_first_arg<_Tp, typename _Tp::value_type>::type,
65 "allocator_traits<A>::rebind_alloc<A::value_type> must be A");
68 template<
typename _Tp,
typename _Up>
69 struct __rebind<_Tp, _Up,
70 __void_t<typename _Tp::template rebind<_Up>::other>>
72 using type =
typename _Tp::template rebind<_Up>::other;
74 static_assert(is_same<
75 typename _Tp::template rebind<typename _Tp::value_type>::other,
77 "allocator_traits<A>::rebind_alloc<A::value_type> must be A");
81 template<
typename _Tp>
82 using __pointer =
typename _Tp::pointer;
83 template<
typename _Tp>
84 using __c_pointer =
typename _Tp::const_pointer;
85 template<
typename _Tp>
86 using __v_pointer =
typename _Tp::void_pointer;
87 template<
typename _Tp>
88 using __cv_pointer =
typename _Tp::const_void_pointer;
89 template<
typename _Tp>
90 using __pocca =
typename _Tp::propagate_on_container_copy_assignment;
91 template<
typename _Tp>
92 using __pocma =
typename _Tp::propagate_on_container_move_assignment;
93 template<
typename _Tp>
94 using __pocs =
typename _Tp::propagate_on_container_swap;
95 template<
typename _Tp>
96 using __equal = __type_identity<typename _Tp::is_always_equal>;
102 template<
typename _Alloc,
typename _Tp,
typename... _Args>
106 template<
typename _Alloc,
typename _Tp,
typename,
typename... _Args>
107 static constexpr bool __has_construct_impl =
false;
108 template<
typename _Alloc,
typename _Tp,
typename... _Args>
109 static constexpr bool
110 __has_construct_impl<_Alloc, _Tp,
111 __void_t<__construct_t<_Alloc, _Tp, _Args...>>,
114 template<
typename _Alloc,
typename _Tp,
typename... _Args>
115 static constexpr bool __has_construct
116 = __has_construct_impl<_Alloc, _Tp, void, _Args...>;
117 template<
typename _Tp,
typename... _Args>
120 template<
typename _Tp,
typename,
typename... _Args>
121 static constexpr bool __has_new_expr =
false;
122 template<
typename _Tp,
typename... _Args>
123 static constexpr bool
124 __has_new_expr<_Tp, __void_t<__new_expr_t<_Tp, _Args...>>, _Args...>
126 template<
typename _Alloc,
typename _Tp,
typename... _Args>
127 static constexpr bool __can_construct
128 = __has_construct<_Alloc, _Tp, _Args...>
129 || __has_new_expr<_Tp, void, _Args...>;
132 template<
typename _Alloc,
typename _Up>
134 =
typename __allocator_traits_base::template __rebind<_Alloc, _Up>::type;
143 template<
typename _Alloc>
160 template<
template<
typename>
class _Func,
typename _Tp,
typename =
void>
166 template<
template<
typename>
class _Func,
typename _Tp>
167 struct _Ptr<_Func, _Tp,
__void_t<_Func<_Alloc>>>
173 template<
typename _A2,
typename _PtrT,
typename =
void>
175 {
using type =
typename pointer_traits<_PtrT>::difference_type; };
177 template<
typename _A2,
typename _PtrT>
179 {
using type =
typename _A2::difference_type; };
182 template<
typename _A2,
typename _DiffT,
typename =
void>
183 struct _Size : make_unsigned<_DiffT> { };
185 template<
typename _A2,
typename _DiffT>
186 struct _Size<_A2, _DiffT, __void_t<typename _A2::
size_type>>
187 {
using type =
typename _A2::size_type; };
228 using size_type =
typename _Size<_Alloc, difference_type>::type;
266 template<
typename _Tp>
268 template<
typename _Tp>
272 template<
typename _Alloc2>
273 static constexpr auto
275 ->
decltype(__a.allocate(__n,
__hint))
276 {
return __a.allocate(__n,
__hint); }
278 template<
typename _Alloc2>
281 {
return __a.allocate(__n); }
284 template<
typename _Alloc2,
typename _Tp>
285 static _GLIBCXX14_CONSTEXPR
auto
286 _S_destroy(_Alloc2& __a, _Tp* __p,
int)
287 noexcept(
noexcept(__a.destroy(__p)))
288 ->
decltype(__a.destroy(__p))
289 { __a.destroy(__p); }
291 template<
typename _Alloc2,
typename _Tp>
292 static _GLIBCXX14_CONSTEXPR
void
293 _S_destroy(_Alloc2&, _Tp* __p, ...)
294 noexcept(
std::is_nothrow_destructible<_Tp>::value)
297 template<
typename _Alloc2>
298 static constexpr auto
299 _S_max_size(_Alloc2& __a,
int)
300 ->
decltype(__a.max_size())
301 {
return __a.max_size(); }
303 template<
typename _Alloc2>
305 _S_max_size(_Alloc2&, ...)
309 return __gnu_cxx::__numeric_traits<size_type>::__max
313 template<
typename _Alloc2>
314 static constexpr auto
315 _S_select(_Alloc2& __a,
int)
316 ->
decltype(__a.select_on_container_copy_construction())
317 {
return __a.select_on_container_copy_construction(); }
319 template<
typename _Alloc2>
320 static constexpr _Alloc2
321 _S_select(_Alloc2& __a, ...)
333 _GLIBCXX_NODISCARD
static _GLIBCXX20_CONSTEXPR
pointer
335 {
return __a.allocate(__n); }
350 {
return _S_allocate(__a, __n,
__hint, 0); }
362 { __a.deallocate(__p, __n); }
375 template<
typename _Tp,
typename...
_Args>
379 noexcept(_S_nothrow_construct<_Tp,
_Args...>())
395 template<
typename _Tp>
398 noexcept(
noexcept(_S_destroy(__a, __p, 0)))
399 { _S_destroy(__a, __p, 0); }
411 {
return _S_max_size(__a, 0); }
423 {
return _S_select(
__rhs, 0); }
426#if __cpp_constexpr >= 201304
427 template<
typename _Tp,
typename...
_Args>
428 static constexpr bool
429 _S_nothrow_construct(_Alloc* __a =
nullptr, _Tp* __p =
nullptr)
434 return __is_nothrow_new_constructible<_Tp,
_Args...>;
437 template<
typename _Tp,
typename... _Args>
439 __enable_if_t<__has_construct<_Alloc, _Tp, _Args...>,
bool>
440 _S_nothrow_construct(_Alloc* __a =
nullptr, _Tp* __p =
nullptr)
443 template<
typename _Tp,
typename... _Args>
445 __enable_if_t<!__has_construct<_Alloc, _Tp, _Args...>,
bool>
446 _S_nothrow_construct(_Alloc* =
nullptr, _Tp* __p =
nullptr)
447 {
return __is_nothrow_new_constructible<_Tp, _Args...>; }
450#pragma GCC diagnostic pop
460 template<
typename _Tp>
499 template<
typename _Up>
502 template<
typename _Up>
515 {
return __a.allocate(__n); }
532#if __cplusplus <= 201703L
533 return __a.allocate(__n,
__hint);
535 return __a.allocate(__n);
547 [[__gnu__::__always_inline__]]
550 { __a.deallocate(__p, __n); }
563 template<
typename _Up,
typename...
_Args>
564 [[__gnu__::__always_inline__]]
568#if __cplusplus <= 201703L
571 noexcept(__is_nothrow_new_constructible<_Up,
_Args...>)
574#if __cplusplus <= 201703L
576#elif __cpp_constexpr_dynamic_alloc
590 template<
typename _Up>
591 [[__gnu__::__always_inline__]]
596#if __cplusplus <= 201703L
599 std::destroy_at(__p);
608 [[__gnu__::__always_inline__]]
612#if __cplusplus <= 201703L
613 return __a.max_size();
624 [[__gnu__::__always_inline__]]
676 template<
typename _Up>
679 template<
typename _Up>
701 template<
typename _Up,
typename...
_Args>
702 [[__gnu__::__always_inline__]]
705 noexcept(__is_nothrow_new_constructible<_Up,
_Args...>)
715 template<
typename _Up>
716 [[__gnu__::__always_inline__]]
731 [[__gnu__::__always_inline__]]
739#if __cplusplus < 201703L
740 template<
typename _Alloc>
741 [[__gnu__::__always_inline__]]
743 __do_alloc_on_copy(_Alloc& __one,
const _Alloc& __two,
true_type)
746 template<
typename _Alloc>
747 [[__gnu__::__always_inline__]]
749 __do_alloc_on_copy(_Alloc&,
const _Alloc&,
false_type)
753 template<
typename _Alloc>
754 [[__gnu__::__always_inline__]]
755 _GLIBCXX14_CONSTEXPR
inline void
756 __alloc_on_copy(_Alloc& __one,
const _Alloc& __two)
758 using __traits = allocator_traits<_Alloc>;
760 typename __traits::propagate_on_container_copy_assignment::type;
761#if __cplusplus >= 201703L
762 if constexpr (__pocca::value)
765 __do_alloc_on_copy(__one, __two, __pocca());
769 template<
typename _Alloc>
770 [[__gnu__::__always_inline__]]
772 __alloc_on_copy(
const _Alloc& __a)
774 typedef allocator_traits<_Alloc> __traits;
775 return __traits::select_on_container_copy_construction(__a);
778#if __cplusplus < 201703L
779 template<
typename _Alloc>
780 [[__gnu__::__always_inline__]]
781 inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two,
true_type)
784 template<
typename _Alloc>
785 [[__gnu__::__always_inline__]]
786 inline void __do_alloc_on_move(_Alloc&, _Alloc&,
false_type)
790 template<
typename _Alloc>
791 [[__gnu__::__always_inline__]]
792 _GLIBCXX14_CONSTEXPR
inline void
793 __alloc_on_move(_Alloc& __one, _Alloc& __two)
795 using __traits = allocator_traits<_Alloc>;
797 =
typename __traits::propagate_on_container_move_assignment::type;
798#if __cplusplus >= 201703L
799 if constexpr (__pocma::value)
802 __do_alloc_on_move(__one, __two, __pocma());
806#if __cplusplus < 201703L
807 template<
typename _Alloc>
808 [[__gnu__::__always_inline__]]
809 inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two,
true_type)
815 template<
typename _Alloc>
816 [[__gnu__::__always_inline__]]
817 inline void __do_alloc_on_swap(_Alloc&, _Alloc&,
false_type)
821 template<
typename _Alloc>
822 [[__gnu__::__always_inline__]]
823 _GLIBCXX14_CONSTEXPR
inline void
824 __alloc_on_swap(_Alloc& __one, _Alloc& __two)
826 using __traits = allocator_traits<_Alloc>;
827 using __pocs =
typename __traits::propagate_on_container_swap::type;
828#if __cplusplus >= 201703L
829 if constexpr (__pocs::value)
835 __do_alloc_on_swap(__one, __two, __pocs());
839 template<
typename _Alloc,
typename _Tp,
840 typename _ValueT = __remove_cvref_t<typename _Alloc::value_type>,
842 struct __is_alloc_insertable_impl
846 template<
typename _Alloc,
typename _Tp,
typename _ValueT>
847 struct __is_alloc_insertable_impl<_Alloc, _Tp, _ValueT,
848 __void_t<decltype(allocator_traits<_Alloc>::construct(
849 std::declval<_Alloc&>(), std::declval<_ValueT*>(),
850 std::declval<_Tp>()))>>
857 template<
typename _Alloc>
858 struct __is_copy_insertable
859 : __is_alloc_insertable_impl<_Alloc,
860 typename _Alloc::value_type const&>::type
865 template<
typename _Tp>
866 struct __is_copy_insertable<allocator<_Tp>>
867 : is_copy_constructible<_Tp>
874 template<
typename _Alloc>
875 struct __is_move_insertable
876 : __is_alloc_insertable_impl<_Alloc, typename _Alloc::value_type>::type
881 template<
typename _Tp>
882 struct __is_move_insertable<allocator<_Tp>>
883 : is_move_constructible<_Tp>
888 template<
typename _Alloc,
typename =
void>
891 template<
typename _Alloc>
892 struct __is_allocator<_Alloc,
893 __void_t<typename _Alloc::value_type,
894 decltype(std::declval<_Alloc&>().allocate(size_t{}))>>
897 template<
typename _Alloc>
898 using _RequireAllocator
899 =
typename enable_if<__is_allocator<_Alloc>::value, _Alloc>::type;
901 template<
typename _Alloc>
902 using _RequireNotAllocator
903 =
typename enable_if<!__is_allocator<_Alloc>::value, _Alloc>::type;
905#if __cpp_concepts >= 201907L
906 template<
typename _Alloc>
907 concept __allocator_like =
requires (_Alloc& __a) {
908 typename _Alloc::value_type;
909 __a.deallocate(__a.allocate(1u), 1u);
918 template<
typename _Alloc,
bool = __is_empty(_Alloc)>
920 {
static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } };
922 template<
typename _Alloc>
923 struct __alloc_swap<_Alloc, false>
926 _S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT
934#if __cplusplus >= 201103L
935 template<
typename _Tp,
bool
936 = __or_<is_copy_constructible<typename _Tp::value_type>,
937 is_nothrow_move_constructible<typename _Tp::value_type>>::value>
938 struct __shrink_to_fit_aux
939 {
static bool _S_do_it(_Tp&)
noexcept {
return false; } };
941 template<
typename _Tp>
942 struct __shrink_to_fit_aux<_Tp, true>
946 _S_do_it(_Tp& __c)
noexcept
951 _Tp(__make_move_if_noexcept_iterator(__c.begin()),
952 __make_move_if_noexcept_iterator(__c.end()),
953 __c.get_allocator()).swap(__c);
971 template<
typename _ForwardIterator,
typename _Allocator>
974 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
977 for (; __first != __last; ++__first)
978#
if __cplusplus < 201103L
987 template<
typename _ForwardIterator,
typename _Tp>
988 __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
990 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
998_GLIBCXX_END_NAMESPACE_VERSION
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
constexpr void _Construct(_Tp *__p, _Args &&... __args)
constexpr void _Destroy(_ForwardIterator __first, _ForwardIterator __last)
Uniform interface to all allocator types.
typename _Ptr< __v_pointer, void >::type void_pointer
The allocator's void pointer type.
__detected_or_t< value_type *, __pointer, _Alloc > pointer
The allocator's pointer type.
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
static constexpr pointer allocate(_Alloc &__a, size_type __n, const_void_pointer __hint)
Allocate memory.
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.
static constexpr __enable_if_t< __can_construct< _Alloc, _Tp, _Args... > > construct(_Alloc &__a, _Tp *__p, _Args &&... __args) noexcept(_S_nothrow_construct< _Tp, _Args... >())
Construct an object of type _Tp
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 constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
typename __detected_or_t< is_empty< _Alloc >, __equal, _Alloc >::type is_always_equal
Whether all instances of the allocator type compare equal.
static constexpr size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
static constexpr void destroy(_Alloc &__a, _Tp *__p) noexcept(noexcept(_S_destroy(__a, __p, 0)))
Destroy an object of type _Tp.
static constexpr _Alloc select_on_container_copy_construction(const _Alloc &__rhs)
Obtain an allocator to use when copying a container.
_Alloc allocator_type
The allocator type.
allocator< _Tp > allocator_type
The allocator type.
static constexpr void construct(allocator_type &__a, _Up *__p, _Args &&... __args) noexcept(__is_nothrow_new_constructible< _Up, _Args... >)
Construct an object of type _Up
_Tp * pointer
The allocator's pointer type.
false_type propagate_on_container_swap
How the allocator is propagated on swap.
static constexpr pointer allocate(allocator_type &__a, size_type __n)
Allocate memory.
_Tp value_type
The allocated type.
static constexpr pointer allocate(allocator_type &__a, size_type __n, const_void_pointer __hint)
Allocate memory.
true_type is_always_equal
Whether all instances of the allocator type compare equal.
const _Tp * const_pointer
The allocator's const pointer type.
true_type propagate_on_container_move_assignment
How the allocator is propagated on move assignment.
static constexpr void deallocate(allocator_type &__a, pointer __p, size_type __n)
Deallocate memory.
static constexpr size_type max_size(const allocator_type &__a) noexcept
The maximum supported allocation size.
static constexpr allocator_type select_on_container_copy_construction(const allocator_type &__rhs)
Obtain an allocator to use when copying a container.
static constexpr void destroy(allocator_type &__a, _Up *__p) noexcept(is_nothrow_destructible< _Up >::value)
Destroy an object of type _Up.
false_type propagate_on_container_copy_assignment
How the allocator is propagated on copy assignment.
std::size_t size_type
The allocator's size type.
false_type propagate_on_container_copy_assignment
How the allocator is propagated on copy assignment.
static void deallocate(allocator_type &, void *, size_type)=delete
deallocate is ill-formed for allocator<void>
true_type is_always_equal
Whether all instances of the allocator type compare equal.
static size_type max_size(const allocator_type &)=delete
max_size is ill-formed for allocator<void>
std::size_t size_type
The allocator's size type.
true_type propagate_on_container_move_assignment
How the allocator is propagated on move assignment.
static void * allocate(allocator_type &, size_type, const void *=nullptr)=delete
allocate is ill-formed for allocator<void>
static constexpr allocator_type select_on_container_copy_construction(const allocator_type &__rhs)
Obtain an allocator to use when copying a container.
static constexpr void construct(allocator_type &, _Up *__p, _Args &&... __args) noexcept(__is_nothrow_new_constructible< _Up, _Args... >)
Construct an object of type _Up
static constexpr void destroy(allocator_type &, _Up *__p) noexcept(is_nothrow_destructible< _Up >::value)
Destroy an object of type _Up
false_type propagate_on_container_swap
How the allocator is propagated on swap.
The standard allocator, as per C++03 [20.4.1].
Uniform interface to all pointer-like types.