30#ifndef _ALLOC_TRAITS_H
31#define _ALLOC_TRAITS_H 1
35#if __cplusplus >= 201103L
43namespace std _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
47#if __cplusplus >= 201103L
48#define __cpp_lib_allocator_traits_is_always_equal 201411L
51 struct __allocator_traits_base
53 template<
typename _Tp,
typename _Up,
typename =
void>
54 struct __rebind : __replace_first_arg<_Tp, _Up> { };
56 template<
typename _Tp,
typename _Up>
57 struct __rebind<_Tp, _Up,
58 __void_t<typename _Tp::template rebind<_Up>::other>>
59 {
using type =
typename _Tp::template rebind<_Up>::other; };
62 template<
typename _Tp>
63 using __pointer =
typename _Tp::pointer;
64 template<
typename _Tp>
65 using __c_pointer =
typename _Tp::const_pointer;
66 template<
typename _Tp>
67 using __v_pointer =
typename _Tp::void_pointer;
68 template<
typename _Tp>
69 using __cv_pointer =
typename _Tp::const_void_pointer;
70 template<
typename _Tp>
71 using __pocca =
typename _Tp::propagate_on_container_copy_assignment;
72 template<
typename _Tp>
73 using __pocma =
typename _Tp::propagate_on_container_move_assignment;
74 template<
typename _Tp>
75 using __pocs =
typename _Tp::propagate_on_container_swap;
76 template<
typename _Tp>
77 using __equal = __type_identity<typename _Tp::is_always_equal>;
80 template<
typename _Alloc,
typename _Up>
82 =
typename __allocator_traits_base::template __rebind<_Alloc, _Up>::type;
91 template<
typename _Alloc>
104 using pointer = __detected_or_t<value_type*, __pointer, _Alloc>;
108 template<
template<
typename>
class _Func,
typename _Tp,
typename =
void>
114 template<
template<
typename>
class _Func,
typename _Tp>
115 struct _Ptr<_Func, _Tp, __void_t<_Func<_Alloc>>>
117 using type = _Func<_Alloc>;
121 template<
typename _A2,
typename _PtrT,
typename =
void>
123 {
using type =
typename pointer_traits<_PtrT>::difference_type; };
125 template<
typename _A2,
typename _PtrT>
127 {
using type =
typename _A2::difference_type; };
130 template<
typename _A2,
typename _DiffT,
typename =
void>
131 struct _Size : make_unsigned<_DiffT> { };
133 template<
typename _A2,
typename _DiffT>
134 struct _Size<_A2, _DiffT, __void_t<typename _A2::
size_type>>
135 {
using type =
typename _A2::size_type; };
176 using size_type =
typename _Size<_Alloc, difference_type>::type;
185 = __detected_or_t<false_type, __pocca, _Alloc>;
194 = __detected_or_t<false_type, __pocma, _Alloc>;
203 = __detected_or_t<false_type, __pocs, _Alloc>;
212 =
typename __detected_or_t<is_empty<_Alloc>, __equal, _Alloc>::type;
214 template<
typename _Tp>
215 using rebind_alloc = __alloc_rebind<_Alloc, _Tp>;
216 template<
typename _Tp>
220 template<
typename _Alloc2>
221 static constexpr auto
223 ->
decltype(__a.allocate(__n, __hint))
224 {
return __a.
allocate(__n, __hint); }
226 template<
typename _Alloc2>
229 {
return __a.allocate(__n); }
231 template<
typename _Tp,
typename... _Args>
232 struct __construct_helper
234 template<
typename _Alloc2,
235 typename =
decltype(std::declval<_Alloc2*>()->construct(
236 std::declval<_Tp*>(), std::declval<_Args>()...))>
242 using type =
decltype(__test<_Alloc>(0));
245 template<
typename _Tp,
typename... _Args>
246 using __has_construct
247 =
typename __construct_helper<_Tp, _Args...>::type;
249 template<
typename _Tp,
typename... _Args>
250 static _GLIBCXX14_CONSTEXPR _Require<__has_construct<_Tp, _Args...>>
251 _S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
252 noexcept(
noexcept(__a.construct(__p, std::forward<_Args>(__args)...)))
253 { __a.construct(__p, std::forward<_Args>(__args)...); }
255 template<
typename _Tp,
typename... _Args>
256 static _GLIBCXX14_CONSTEXPR
257 _Require<__and_<__not_<__has_construct<_Tp, _Args...>>,
258 is_constructible<_Tp, _Args...>>>
259 _S_construct(_Alloc&, _Tp* __p, _Args&&... __args)
262#if __cplusplus <= 201703L
263 ::new((
void*)__p) _Tp(std::forward<_Args>(__args)...);
265 std::construct_at(__p, std::forward<_Args>(__args)...);
269 template<
typename _Alloc2,
typename _Tp>
270 static _GLIBCXX14_CONSTEXPR
auto
271 _S_destroy(_Alloc2& __a, _Tp* __p,
int)
272 noexcept(
noexcept(__a.destroy(__p)))
273 ->
decltype(__a.destroy(__p))
274 { __a.destroy(__p); }
276 template<
typename _Alloc2,
typename _Tp>
277 static _GLIBCXX14_CONSTEXPR
void
278 _S_destroy(_Alloc2&, _Tp* __p, ...)
279 noexcept(
std::is_nothrow_destructible<_Tp>::value)
282 template<
typename _Alloc2>
283 static constexpr auto
284 _S_max_size(_Alloc2& __a,
int)
285 ->
decltype(__a.max_size())
286 {
return __a.max_size(); }
288 template<
typename _Alloc2>
290 _S_max_size(_Alloc2&, ...)
294 return __gnu_cxx::__numeric_traits<size_type>::__max
298 template<
typename _Alloc2>
299 static constexpr auto
300 _S_select(_Alloc2& __a,
int)
301 ->
decltype(__a.select_on_container_copy_construction())
302 {
return __a.select_on_container_copy_construction(); }
304 template<
typename _Alloc2>
305 static constexpr _Alloc2
306 _S_select(_Alloc2& __a, ...)
318 _GLIBCXX_NODISCARD
static _GLIBCXX20_CONSTEXPR
pointer
320 {
return __a.allocate(__n); }
333 _GLIBCXX_NODISCARD
static _GLIBCXX20_CONSTEXPR
pointer
335 {
return _S_allocate(__a, __n, __hint, 0); }
345 static _GLIBCXX20_CONSTEXPR
void
347 { __a.deallocate(__p, __n); }
360 template<
typename _Tp,
typename... _Args>
361 static _GLIBCXX20_CONSTEXPR
auto
363 noexcept(
noexcept(_S_construct(__a, __p,
364 std::forward<_Args>(__args)...)))
365 ->
decltype(_S_construct(__a, __p, std::forward<_Args>(__args)...))
366 { _S_construct(__a, __p, std::forward<_Args>(__args)...); }
376 template<
typename _Tp>
377 static _GLIBCXX20_CONSTEXPR
void
379 noexcept(
noexcept(_S_destroy(__a, __p, 0)))
380 { _S_destroy(__a, __p, 0); }
392 {
return _S_max_size(__a, 0); }
402 static _GLIBCXX20_CONSTEXPR _Alloc
404 {
return _S_select(__rhs, 0); }
409#if __cplusplus > 201703L
410# define __cpp_lib_constexpr_dynamic_alloc 201907L
414 template<
typename _Tp>
453 template<
typename _Up>
456 template<
typename _Up>
466 [[__nodiscard__,__gnu__::__always_inline__]]
467 static _GLIBCXX20_CONSTEXPR
pointer
469 {
return __a.allocate(__n); }
481 [[__nodiscard__,__gnu__::__always_inline__]]
482 static _GLIBCXX20_CONSTEXPR
pointer
485#if __cplusplus <= 201703L
486 return __a.allocate(__n, __hint);
488 return __a.allocate(__n);
500 [[__gnu__::__always_inline__]]
501 static _GLIBCXX20_CONSTEXPR
void
503 { __a.deallocate(__p, __n); }
516 template<
typename _Up,
typename... _Args>
517 [[__gnu__::__always_inline__]]
518 static _GLIBCXX20_CONSTEXPR
void
523#if __cplusplus <= 201703L
524 __a.construct(__p, std::forward<_Args>(__args)...);
526 std::construct_at(__p, std::forward<_Args>(__args)...);
537 template<
typename _Up>
538 [[__gnu__::__always_inline__]]
539 static _GLIBCXX20_CONSTEXPR
void
543#if __cplusplus <= 201703L
546 std::destroy_at(__p);
555 [[__gnu__::__always_inline__]]
559#if __cplusplus <= 201703L
560 return __a.max_size();
571 [[__gnu__::__always_inline__]]
617 template<
typename _Up>
620 template<
typename _Up>
642 template<
typename _Up,
typename... _Args>
643 [[__gnu__::__always_inline__]]
644 static _GLIBCXX20_CONSTEXPR
void
656 template<
typename _Up>
657 [[__gnu__::__always_inline__]]
658 static _GLIBCXX20_CONSTEXPR
void
672 [[__gnu__::__always_inline__]]
680#if __cplusplus < 201703L
681 template<
typename _Alloc>
682 [[__gnu__::__always_inline__]]
684 __do_alloc_on_copy(_Alloc& __one,
const _Alloc& __two,
true_type)
687 template<
typename _Alloc>
688 [[__gnu__::__always_inline__]]
690 __do_alloc_on_copy(_Alloc&,
const _Alloc&,
false_type)
694 template<
typename _Alloc>
695 [[__gnu__::__always_inline__]]
696 _GLIBCXX14_CONSTEXPR
inline void
697 __alloc_on_copy(_Alloc& __one,
const _Alloc& __two)
699 using __traits = allocator_traits<_Alloc>;
701 typename __traits::propagate_on_container_copy_assignment::type;
702#if __cplusplus >= 201703L
703 if constexpr (__pocca::value)
706 __do_alloc_on_copy(__one, __two, __pocca());
710 template<
typename _Alloc>
711 [[__gnu__::__always_inline__]]
713 __alloc_on_copy(
const _Alloc& __a)
715 typedef allocator_traits<_Alloc> __traits;
716 return __traits::select_on_container_copy_construction(__a);
719#if __cplusplus < 201703L
720 template<
typename _Alloc>
721 [[__gnu__::__always_inline__]]
722 inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two,
true_type)
725 template<
typename _Alloc>
726 [[__gnu__::__always_inline__]]
727 inline void __do_alloc_on_move(_Alloc&, _Alloc&,
false_type)
731 template<
typename _Alloc>
732 [[__gnu__::__always_inline__]]
733 _GLIBCXX14_CONSTEXPR
inline void
734 __alloc_on_move(_Alloc& __one, _Alloc& __two)
736 using __traits = allocator_traits<_Alloc>;
738 =
typename __traits::propagate_on_container_move_assignment::type;
739#if __cplusplus >= 201703L
740 if constexpr (__pocma::value)
743 __do_alloc_on_move(__one, __two, __pocma());
747#if __cplusplus < 201703L
748 template<
typename _Alloc>
749 [[__gnu__::__always_inline__]]
750 inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two,
true_type)
756 template<
typename _Alloc>
757 [[__gnu__::__always_inline__]]
758 inline void __do_alloc_on_swap(_Alloc&, _Alloc&,
false_type)
762 template<
typename _Alloc>
763 [[__gnu__::__always_inline__]]
764 _GLIBCXX14_CONSTEXPR
inline void
765 __alloc_on_swap(_Alloc& __one, _Alloc& __two)
767 using __traits = allocator_traits<_Alloc>;
768 using __pocs =
typename __traits::propagate_on_container_swap::type;
769#if __cplusplus >= 201703L
770 if constexpr (__pocs::value)
776 __do_alloc_on_swap(__one, __two, __pocs());
780 template<
typename _Alloc,
typename _Tp,
781 typename _ValueT = __remove_cvref_t<typename _Alloc::value_type>,
783 struct __is_alloc_insertable_impl
787 template<
typename _Alloc,
typename _Tp,
typename _ValueT>
788 struct __is_alloc_insertable_impl<_Alloc, _Tp, _ValueT,
789 __void_t<decltype(allocator_traits<_Alloc>::construct(
790 std::declval<_Alloc&>(), std::declval<_ValueT*>(),
791 std::declval<_Tp>()))>>
798 template<
typename _Alloc>
799 struct __is_copy_insertable
800 : __is_alloc_insertable_impl<_Alloc,
801 typename _Alloc::value_type const&>::type
806 template<
typename _Tp>
807 struct __is_copy_insertable<allocator<_Tp>>
808 : is_copy_constructible<_Tp>
815 template<
typename _Alloc>
816 struct __is_move_insertable
817 : __is_alloc_insertable_impl<_Alloc, typename _Alloc::value_type>::type
822 template<
typename _Tp>
823 struct __is_move_insertable<allocator<_Tp>>
824 : is_move_constructible<_Tp>
829 template<
typename _Alloc,
typename =
void>
832 template<
typename _Alloc>
833 struct __is_allocator<_Alloc,
834 __void_t<typename _Alloc::value_type,
835 decltype(std::declval<_Alloc&>().allocate(size_t{}))>>
838 template<
typename _Alloc>
839 using _RequireAllocator
840 =
typename enable_if<__is_allocator<_Alloc>::value, _Alloc>::type;
842 template<
typename _Alloc>
843 using _RequireNotAllocator
844 =
typename enable_if<!__is_allocator<_Alloc>::value, _Alloc>::type;
846#if __cpp_concepts >= 201907L
847 template<
typename _Alloc>
848 concept __allocator_like =
requires (_Alloc& __a) {
849 typename _Alloc::value_type;
850 __a.deallocate(__a.allocate(1u), 1u);
859 template<
typename _Alloc,
bool = __is_empty(_Alloc)>
861 {
static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } };
863 template<
typename _Alloc>
864 struct __alloc_swap<_Alloc, false>
867 _S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT
875#if __cplusplus >= 201103L
876 template<
typename _Tp,
bool
877 = __or_<is_copy_constructible<typename _Tp::value_type>,
878 is_nothrow_move_constructible<typename _Tp::value_type>>::value>
879 struct __shrink_to_fit_aux
880 {
static bool _S_do_it(_Tp&)
noexcept {
return false; } };
882 template<
typename _Tp>
883 struct __shrink_to_fit_aux<_Tp, true>
887 _S_do_it(_Tp& __c)
noexcept
892 _Tp(__make_move_if_noexcept_iterator(__c.begin()),
893 __make_move_if_noexcept_iterator(__c.end()),
894 __c.get_allocator()).swap(__c);
912 template<
typename _ForwardIterator,
typename _Allocator>
915 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
918 for (; __first != __last; ++__first)
919#
if __cplusplus < 201103L
928 template<
typename _ForwardIterator,
typename _Tp>
929 __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
931 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
939_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.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
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.
static constexpr 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, __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.
__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.
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.
__detected_or_t< false_type, __pocca, _Alloc > propagate_on_container_copy_assignment
How the allocator is propagated on copy assignment.
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.
__detected_or_t< false_type, __pocs, _Alloc > propagate_on_container_swap
How the allocator is propagated on swap.
_Alloc allocator_type
The allocator type.
allocator< _Tp > allocator_type
The allocator type.
void * void_pointer
The allocator's void pointer type.
_Tp * pointer
The allocator's pointer type.
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.
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 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 construct(allocator_type &__a, _Up *__p, _Args &&... __args) noexcept(std::is_nothrow_constructible< _Up, _Args... >::value)
Construct an object of type _Up
static constexpr void destroy(allocator_type &__a, _Up *__p) noexcept(is_nothrow_destructible< _Up >::value)
Destroy an object of type _Up.
std::size_t size_type
The allocator's size type.
void * pointer
The allocator's pointer type.
void * void_pointer
The allocator's void pointer type.
static void deallocate(allocator_type &, void *, size_type)=delete
deallocate is ill-formed for allocator<void>
static constexpr void construct(allocator_type &, _Up *__p, _Args &&... __args) noexcept(std::is_nothrow_constructible< _Up, _Args... >::value)
Construct an object of type _Up
void value_type
The allocated type.
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.
const void * const_pointer
The allocator's const pointer type.
std::ptrdiff_t difference_type
The allocator's difference type.
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.
const void * const_void_pointer
The allocator's const void pointer type.
static constexpr void destroy(allocator_type &, _Up *__p) noexcept(is_nothrow_destructible< _Up >::value)
Destroy an object of type _Up
The standard allocator, as per C++03 [20.4.1].
Uniform interface to all pointer-like types.