30#ifndef _USES_ALLOCATOR_H
31#define _USES_ALLOCATOR_H 1
33#if __cplusplus < 201103L
40namespace std _GLIBCXX_VISIBILITY(default)
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
46 struct __erased_type { };
51 template<
typename _Alloc,
typename _Tp>
52 using __is_erased_or_convertible
56 struct allocator_arg_t {
explicit allocator_arg_t() =
default; };
58 _GLIBCXX17_INLINE
constexpr allocator_arg_t allocator_arg =
61 template<
typename _Tp,
typename _Alloc,
typename = __
void_t<>>
62 struct __uses_allocator_helper
65 template<
typename _Tp,
typename _Alloc>
66 struct __uses_allocator_helper<_Tp, _Alloc,
67 __void_t<typename _Tp::allocator_type>>
68 : __is_erased_or_convertible<_Alloc, typename _Tp::allocator_type>::type
72 template<
typename _Tp,
typename _Alloc>
74 : __uses_allocator_helper<_Tp, _Alloc>::type
77 struct __uses_alloc_base { };
79 struct __uses_alloc0 : __uses_alloc_base
81 struct _Sink {
void _GLIBCXX20_CONSTEXPR operator=(
const void*) { } } _M_a;
84 template<
typename _Alloc>
85 struct __uses_alloc1 : __uses_alloc_base {
const _Alloc* _M_a; };
87 template<
typename _Alloc>
88 struct __uses_alloc2 : __uses_alloc_base {
const _Alloc* _M_a; };
90 template<bool,
typename _Tp,
typename _Alloc,
typename... _Args>
93 template<
typename _Tp,
typename _Alloc,
typename... _Args>
94 struct __uses_alloc<true, _Tp, _Alloc, _Args...>
96 is_constructible<_Tp, allocator_arg_t, const _Alloc&, _Args...>::value,
97 __uses_alloc1<_Alloc>,
98 __uses_alloc2<_Alloc>>
103 is_constructible<_Tp, allocator_arg_t,
const _Alloc&, _Args...>,
104 is_constructible<_Tp, _Args...,
const _Alloc&>>::value,
105 "construction with an allocator must be possible"
106 " if uses_allocator is true");
109 template<
typename _Tp,
typename _Alloc,
typename... _Args>
110 struct __uses_alloc<false, _Tp, _Alloc, _Args...>
113 template<
typename _Tp,
typename _Alloc,
typename... _Args>
114 using __uses_alloc_t =
115 __uses_alloc<uses_allocator<_Tp, _Alloc>::value, _Tp, _Alloc, _Args...>;
117 template<
typename _Tp,
typename _Alloc,
typename... _Args>
119 inline __uses_alloc_t<_Tp, _Alloc, _Args...>
120 __use_alloc(
const _Alloc& __a)
122 __uses_alloc_t<_Tp, _Alloc, _Args...> __ret;
127 template<
typename _Tp,
typename _Alloc,
typename... _Args>
129 __use_alloc(
const _Alloc&&) =
delete;
131#if __cplusplus > 201402L
132 template <
typename _Tp,
typename _Alloc>
133 inline constexpr bool uses_allocator_v =
138 template<
typename _Alloc,
typename... _Ts>
139 concept __allocator_for = (uses_allocator_v<_Ts, _Alloc> && ...);
142 template<
template<
typename...>
class _Predicate,
143 typename _Tp,
typename _Alloc,
typename... _Args>
144 struct __is_uses_allocator_predicate
145 : __conditional_t<uses_allocator<_Tp, _Alloc>::value,
146 __or_<_Predicate<_Tp, allocator_arg_t, _Alloc, _Args...>,
147 _Predicate<_Tp, _Args..., _Alloc>>,
148 _Predicate<_Tp, _Args...>> { };
150 template<
typename _Tp,
typename _Alloc,
typename... _Args>
151 struct __is_uses_allocator_constructible
152 : __is_uses_allocator_predicate<is_constructible, _Tp, _Alloc, _Args...>
155#if __cplusplus >= 201402L
156 template<
typename _Tp,
typename _Alloc,
typename... _Args>
157 _GLIBCXX17_INLINE
constexpr bool __is_uses_allocator_constructible_v =
158 __is_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
161 template<
typename _Tp,
typename _Alloc,
typename... _Args>
162 struct __is_nothrow_uses_allocator_constructible
163 : __is_uses_allocator_predicate<is_nothrow_constructible,
164 _Tp, _Alloc, _Args...>
168#if __cplusplus >= 201402L
169 template<
typename _Tp,
typename _Alloc,
typename... _Args>
170 _GLIBCXX17_INLINE
constexpr bool
171 __is_nothrow_uses_allocator_constructible_v =
172 __is_nothrow_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
175 template<
typename _Tp,
typename... _Args>
176 void __uses_allocator_construct_impl(__uses_alloc0, _Tp* __ptr,
180 template<
typename _Tp,
typename _Alloc,
typename... _Args>
181 void __uses_allocator_construct_impl(__uses_alloc1<_Alloc> __a, _Tp* __ptr,
184 ::new ((
void*)__ptr) _Tp(allocator_arg, *__a._M_a,
188 template<
typename _Tp,
typename _Alloc,
typename... _Args>
189 void __uses_allocator_construct_impl(__uses_alloc2<_Alloc> __a, _Tp* __ptr,
193 template<
typename _Tp,
typename _Alloc,
typename... _Args>
194 void __uses_allocator_construct(
const _Alloc& __a, _Tp* __ptr,
197 std::__uses_allocator_construct_impl(
198 std::__use_alloc<_Tp, _Alloc, _Args...>(__a), __ptr,
203_GLIBCXX_END_NAMESPACE_VERSION
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
Declare uses_allocator so it can be specialized in <queue> etc.