30 #ifndef _ALLOC_TRAITS_H 31 #define _ALLOC_TRAITS_H 1 35 #if __cplusplus >= 201103L 41 namespace std _GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45 #if __cplusplus >= 201103L 46 #define __cpp_lib_allocator_traits_is_always_equal 201411 49 struct __allocator_traits_base
51 template<
typename _Tp,
typename _Up,
typename =
void>
52 struct __rebind : __replace_first_arg<_Tp, _Up> { };
54 template<
typename _Tp,
typename _Up>
55 struct __rebind<_Tp, _Up,
56 __void_t<typename _Tp::template rebind<_Up>::other>>
57 {
using type =
typename _Tp::template rebind<_Up>::other; };
60 template<
typename _Tp>
61 using __pointer =
typename _Tp::pointer;
62 template<
typename _Tp>
63 using __c_pointer =
typename _Tp::const_pointer;
64 template<
typename _Tp>
65 using __v_pointer =
typename _Tp::void_pointer;
66 template<
typename _Tp>
67 using __cv_pointer =
typename _Tp::const_void_pointer;
68 template<
typename _Tp>
69 using __pocca =
typename _Tp::propagate_on_container_copy_assignment;
70 template<
typename _Tp>
71 using __pocma =
typename _Tp::propagate_on_container_move_assignment;
72 template<
typename _Tp>
73 using __pocs =
typename _Tp::propagate_on_container_swap;
74 template<
typename _Tp>
75 using __equal =
typename _Tp::is_always_equal;
78 template<
typename _Alloc,
typename _Up>
80 =
typename __allocator_traits_base::template __rebind<_Alloc, _Up>::type;
89 template<
typename _Alloc>
102 using pointer = __detected_or_t<value_type*, __pointer, _Alloc>;
106 template<
template<
typename>
class _Func,
typename _Tp,
typename =
void>
112 template<
template<
typename>
class _Func,
typename _Tp>
113 struct _Ptr<_Func, _Tp, __void_t<_Func<_Alloc>>>
115 using type = _Func<_Alloc>;
119 template<
typename _A2,
typename _PtrT,
typename =
void>
123 template<
typename _A2,
typename _PtrT>
125 {
using type =
typename _A2::difference_type; };
128 template<
typename _A2,
typename _DiffT,
typename =
void>
129 struct _Size : make_unsigned<_DiffT> { };
131 template<
typename _A2,
typename _DiffT>
132 struct _Size<_A2, _DiffT, __void_t<typename _A2::
size_type>>
133 {
using type =
typename _A2::size_type; };
174 using size_type =
typename _Size<_Alloc, difference_type>::type;
183 = __detected_or_t<false_type, __pocca, _Alloc>;
192 = __detected_or_t<false_type, __pocma, _Alloc>;
201 = __detected_or_t<false_type, __pocs, _Alloc>;
210 = __detected_or_t<typename is_empty<_Alloc>::type, __equal, _Alloc>;
212 template<
typename _Tp>
213 using rebind_alloc = __alloc_rebind<_Alloc, _Tp>;
214 template<
typename _Tp>
218 template<
typename _Alloc2>
219 static constexpr
auto 221 -> decltype(__a.allocate(__n, __hint))
222 {
return __a.
allocate(__n, __hint); }
224 template<
typename _Alloc2>
227 {
return __a.allocate(__n); }
229 template<
typename _Tp,
typename... _Args>
230 struct __construct_helper
232 template<
typename _Alloc2,
233 typename = decltype(std::declval<_Alloc2*>()->
construct(
234 std::declval<_Tp*>(), std::declval<_Args>()...))>
240 using type = decltype(__test<_Alloc>(0));
243 template<
typename _Tp,
typename... _Args>
244 using __has_construct
245 =
typename __construct_helper<_Tp, _Args...>::type;
247 template<
typename _Tp,
typename... _Args>
248 static _GLIBCXX14_CONSTEXPR _Require<__has_construct<_Tp, _Args...>>
249 _S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
250 noexcept(noexcept(__a.construct(__p, std::forward<_Args>(__args)...)))
251 { __a.construct(__p, std::forward<_Args>(__args)...); }
253 template<
typename _Tp,
typename... _Args>
254 static _GLIBCXX14_CONSTEXPR
255 _Require<__and_<__not_<__has_construct<_Tp, _Args...>>,
256 is_constructible<_Tp, _Args...>>>
257 _S_construct(_Alloc&, _Tp* __p, _Args&&... __args)
260 #if __cplusplus <= 201703L 261 ::new((
void*)__p) _Tp(std::forward<_Args>(__args)...);
263 std::construct_at(__p, std::forward<_Args>(__args)...);
267 template<
typename _Alloc2,
typename _Tp>
268 static _GLIBCXX14_CONSTEXPR
auto 269 _S_destroy(_Alloc2& __a, _Tp* __p,
int)
270 noexcept(noexcept(__a.destroy(__p)))
271 -> decltype(__a.destroy(__p))
272 { __a.destroy(__p); }
274 template<
typename _Alloc2,
typename _Tp>
275 static _GLIBCXX14_CONSTEXPR
void 276 _S_destroy(_Alloc2&, _Tp* __p, ...)
277 noexcept(
std::is_nothrow_destructible<_Tp>::value)
280 template<
typename _Alloc2>
281 static constexpr
auto 282 _S_max_size(_Alloc2& __a,
int)
283 -> decltype(__a.max_size())
284 {
return __a.max_size(); }
286 template<
typename _Alloc2>
288 _S_max_size(_Alloc2&, ...)
292 return __gnu_cxx::__numeric_traits<size_type>::__max
296 template<
typename _Alloc2>
297 static constexpr
auto 298 _S_select(_Alloc2& __a,
int)
299 -> decltype(__a.select_on_container_copy_construction())
300 {
return __a.select_on_container_copy_construction(); }
302 template<
typename _Alloc2>
303 static constexpr _Alloc2
304 _S_select(_Alloc2& __a, ...)
316 _GLIBCXX_NODISCARD
static _GLIBCXX20_CONSTEXPR
pointer 318 {
return __a.allocate(__n); }
331 _GLIBCXX_NODISCARD
static _GLIBCXX20_CONSTEXPR
pointer 333 {
return _S_allocate(__a, __n, __hint, 0); }
343 static _GLIBCXX20_CONSTEXPR
void 345 { __a.deallocate(__p, __n); }
358 template<
typename _Tp,
typename... _Args>
359 static _GLIBCXX20_CONSTEXPR
auto 361 noexcept(noexcept(_S_construct(__a, __p,
362 std::forward<_Args>(__args)...)))
363 -> decltype(_S_construct(__a, __p, std::forward<_Args>(__args)...))
364 { _S_construct(__a, __p, std::forward<_Args>(__args)...); }
374 template<
typename _Tp>
375 static _GLIBCXX20_CONSTEXPR
void 377 noexcept(noexcept(_S_destroy(__a, __p, 0)))
378 { _S_destroy(__a, __p, 0); }
390 {
return _S_max_size(__a, 0); }
400 static _GLIBCXX20_CONSTEXPR _Alloc
402 {
return _S_select(__rhs, 0); }
405 #if __cplusplus > 201703L 406 # define __cpp_lib_constexpr_dynamic_alloc 201907L 410 template<
typename _Tp>
449 template<
typename _Up>
452 template<
typename _Up>
462 _GLIBCXX_NODISCARD
static _GLIBCXX20_CONSTEXPR
pointer 464 {
return __a.allocate(__n); }
476 _GLIBCXX_NODISCARD
static _GLIBCXX20_CONSTEXPR
pointer 479 #if __cplusplus <= 201703L 480 return __a.allocate(__n, __hint);
482 return __a.allocate(__n);
494 static _GLIBCXX20_CONSTEXPR
void 496 { __a.deallocate(__p, __n); }
509 template<
typename _Up,
typename... _Args>
510 static _GLIBCXX20_CONSTEXPR
void 515 #if __cplusplus <= 201703L 516 __a.construct(__p, std::forward<_Args>(__args)...);
518 std::construct_at(__p, std::forward<_Args>(__args)...);
529 template<
typename _Up>
530 static _GLIBCXX20_CONSTEXPR
void 534 #if __cplusplus <= 201703L 537 std::destroy_at(__p);
549 #if __cplusplus <= 201703L 550 return __a.max_size();
606 template<
typename _Up>
609 template<
typename _Up>
631 template<
typename _Up,
typename... _Args>
632 static _GLIBCXX20_CONSTEXPR
void 636 #if __cplusplus <= 201703L 637 ::new((
void *)__p) _Up(std::forward<_Args>(__args)...);
639 std::construct_at(__p, std::forward<_Args>(__args)...);
650 template<
typename _Up>
651 static _GLIBCXX20_CONSTEXPR
void 670 #if __cplusplus < 201703L 671 template<
typename _Alloc>
673 __do_alloc_on_copy(_Alloc& __one,
const _Alloc& __two,
true_type)
676 template<
typename _Alloc>
678 __do_alloc_on_copy(_Alloc&,
const _Alloc&,
false_type)
682 template<
typename _Alloc>
683 _GLIBCXX14_CONSTEXPR
inline void 684 __alloc_on_copy(_Alloc& __one,
const _Alloc& __two)
686 typedef allocator_traits<_Alloc> __traits;
687 typedef typename __traits::propagate_on_container_copy_assignment __pocca;
688 #if __cplusplus >= 201703L 689 if constexpr (__pocca::value)
692 __do_alloc_on_copy(__one, __two, __pocca());
696 template<
typename _Alloc>
698 __alloc_on_copy(
const _Alloc& __a)
700 typedef allocator_traits<_Alloc> __traits;
701 return __traits::select_on_container_copy_construction(__a);
704 #if __cplusplus < 201703L 705 template<
typename _Alloc>
706 inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two,
true_type)
709 template<
typename _Alloc>
710 inline void __do_alloc_on_move(_Alloc&, _Alloc&,
false_type)
714 template<
typename _Alloc>
715 _GLIBCXX14_CONSTEXPR
inline void 716 __alloc_on_move(_Alloc& __one, _Alloc& __two)
718 typedef allocator_traits<_Alloc> __traits;
719 typedef typename __traits::propagate_on_container_move_assignment __pocma;
720 #if __cplusplus >= 201703L 721 if constexpr (__pocma::value)
724 __do_alloc_on_move(__one, __two, __pocma());
728 #if __cplusplus < 201703L 729 template<
typename _Alloc>
730 inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two,
true_type)
736 template<
typename _Alloc>
737 inline void __do_alloc_on_swap(_Alloc&, _Alloc&,
false_type)
741 template<
typename _Alloc>
742 _GLIBCXX14_CONSTEXPR
inline void 743 __alloc_on_swap(_Alloc& __one, _Alloc& __two)
745 typedef allocator_traits<_Alloc> __traits;
746 typedef typename __traits::propagate_on_container_swap __pocs;
747 #if __cplusplus >= 201703L 748 if constexpr (__pocs::value)
754 __do_alloc_on_swap(__one, __two, __pocs());
758 template<
typename _Alloc,
typename _Tp,
759 typename _ValueT = __remove_cvref_t<typename _Alloc::value_type>,
761 struct __is_alloc_insertable_impl
765 template<
typename _Alloc,
typename _Tp,
typename _ValueT>
766 struct __is_alloc_insertable_impl<_Alloc, _Tp, _ValueT,
767 __void_t<decltype(allocator_traits<_Alloc>::construct(
768 std::declval<_Alloc&>(), std::declval<_ValueT*>(),
769 std::declval<_Tp>()))>>
776 template<
typename _Alloc>
777 struct __is_copy_insertable
778 : __is_alloc_insertable_impl<_Alloc,
779 typename _Alloc::value_type const&>::type
783 template<
typename _Tp>
784 struct __is_copy_insertable<allocator<_Tp>>
785 : is_copy_constructible<_Tp>
791 template<
typename _Alloc>
792 struct __is_move_insertable
793 : __is_alloc_insertable_impl<_Alloc, typename _Alloc::value_type>::type
797 template<
typename _Tp>
798 struct __is_move_insertable<allocator<_Tp>>
799 : is_move_constructible<_Tp>
803 template<
typename _Alloc,
typename =
void>
806 template<
typename _Alloc>
807 struct __is_allocator<_Alloc,
808 __void_t<typename _Alloc::value_type,
809 decltype(std::declval<_Alloc&>().allocate(size_t{}))>>
812 template<
typename _Alloc>
813 using _RequireAllocator
814 =
typename enable_if<__is_allocator<_Alloc>::value, _Alloc>::type;
816 template<
typename _Alloc>
817 using _RequireNotAllocator
818 =
typename enable_if<!__is_allocator<_Alloc>::value, _Alloc>::type;
820 #if __cpp_concepts >= 201907L 821 template<
typename _Alloc>
822 concept __allocator_like = requires (_Alloc& __a) {
823 typename _Alloc::value_type;
824 __a.deallocate(__a.allocate(1u), 1u);
835 template<
typename _ForwardIterator,
typename _Allocator>
837 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
840 for (; __first != __last; ++__first)
841 #
if __cplusplus < 201103L
849 template<
typename _ForwardIterator,
typename _Tp>
851 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
857 _GLIBCXX_END_NAMESPACE_VERSION
859 #endif // _ALLOC_TRAITS_H typename _Ptr< __c_pointer, const value_type >::type const_pointer
The allocator's const pointer type.
typename _Ptr< __cv_pointer, const void >::type const_void_pointer
The allocator's const void pointer type.
static constexpr size_type max_size(const allocator_type &__a) noexcept
The maximum supported allocation size.
void * pointer
The allocator's pointer type.
static constexpr pointer allocate(allocator_type &__a, size_type __n, const_void_pointer __hint)
Allocate memory.
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
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
static constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
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 deallocate(allocator_type &__a, pointer __p, size_type __n)
Deallocate memory.
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
static constexpr size_type max_size(const _Alloc &__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.
void _Destroy(_ForwardIterator __first, _ForwardIterator __last, _Allocator &__alloc)
__detected_or_t< false_type, __pocma, _Tp_alloc_type > propagate_on_container_move_assignment
How the allocator is propagated on move assignment.
const _Tp * const_pointer
The allocator's const pointer type.
_Alloc allocator_type
The allocator type.
typename _Size< _Alloc, difference_type >::type size_type
The allocator's size type.
const void * const_void_pointer
The allocator's const void pointer type.
std::size_t size_type
The allocator's size type.
const void * const_void_pointer
The allocator's const void pointer type.
typename _Diff< _Alloc, pointer >::type difference_type
The allocator's difference type.
Uniform interface to all pointer-like types.
const void * const_pointer
The allocator's const pointer type.
void value_type
The allocated type.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
allocator< _Tp > allocator_type
The allocator type.
allocator<void> specialization.
static constexpr void construct(allocator_type &, _Up *__p, _Args &&... __args) noexcept(std::is_nothrow_constructible< _Up, _Args... >::value)
Construct an object of type _Up
typename _Ptr< __v_pointer, void >::type void_pointer
The allocator's void pointer type.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
The standard allocator, as per C++03 [20.4.1].
static constexpr void destroy(allocator_type &__a, _Up *__p) noexcept(is_nothrow_destructible< _Up >::value)
Destroy an object of type _Up.
_Tp value_type
The allocated type.
Uniform interface to all allocator types.
__detected_or_t< ptrdiff_t, __difference_type, _Ptr > difference_type
The type used to represent the difference between two pointers.
static constexpr void destroy(allocator_type &, _Up *__p) noexcept(is_nothrow_destructible< _Up >::value)
Destroy an object of type _Up
__detected_or_t< false_type, __pocca, _Tp_alloc_type > propagate_on_container_copy_assignment
How the allocator is propagated on copy assignment.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
static constexpr pointer allocate(allocator_type &__a, size_type __n)
Allocate memory.
_Tp * pointer
The allocator's pointer type.
__detected_or_t< value_type *, __pointer, _Tp_alloc_type > pointer
The allocator's pointer type.
__detected_or_t< false_type, __pocs, _Tp_alloc_type > propagate_on_container_swap
How the allocator is propagated on swap.
_Alloc::value_type value_type
The allocated type.
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
static constexpr _Alloc select_on_container_copy_construction(const _Alloc &__rhs)
Obtain an allocator to use when copying a container.
std::ptrdiff_t difference_type
The allocator's difference type.
void * void_pointer
The allocator's void pointer type.
std::ptrdiff_t difference_type
The allocator's difference type.
static constexpr void destroy(_Alloc &__a, _Tp *__p) noexcept(noexcept(_S_destroy(__a, __p, 0)))
Destroy an object of type _Tp.
ISO C++ entities toplevel namespace is std.
std::size_t size_type
The allocator's size type.
__detected_or_t< typename is_empty< _Tp_alloc_type >::type, __equal, _Tp_alloc_type > is_always_equal
Whether all instances of the allocator type compare equal.
void * void_pointer
The allocator's void pointer type.