25 #ifndef _USES_ALLOCATOR_H
26 #define _USES_ALLOCATOR_H 1
28 #if __cplusplus < 201103L
35 namespace std _GLIBCXX_VISIBILITY(default)
37 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 struct __erased_type { };
45 template<
typename _Alloc,
typename _Tp>
46 using __is_erased_or_convertible
47 = __or_<is_convertible<_Alloc, _Tp>, is_same<_Tp, __erased_type>>;
55 template<
typename _Tp,
typename _Alloc,
typename = __
void_t<>>
56 struct __uses_allocator_helper
59 template<
typename _Tp,
typename _Alloc>
60 struct __uses_allocator_helper<_Tp, _Alloc,
61 __void_t<typename _Tp::allocator_type>>
62 : __is_erased_or_convertible<_Alloc, typename _Tp::allocator_type>::type
66 template<
typename _Tp,
typename _Alloc>
68 : __uses_allocator_helper<_Tp, _Alloc>
::type
71 struct __uses_alloc_base { };
73 struct __uses_alloc0 : __uses_alloc_base
75 struct _Sink {
void _GLIBCXX20_CONSTEXPR operator=(
const void*) { } } _M_a;
78 template<
typename _Alloc>
79 struct __uses_alloc1 : __uses_alloc_base {
const _Alloc* _M_a; };
81 template<
typename _Alloc>
82 struct __uses_alloc2 : __uses_alloc_base {
const _Alloc* _M_a; };
84 template<bool,
typename _Tp,
typename _Alloc,
typename... _Args>
87 template<
typename _Tp,
typename _Alloc,
typename... _Args>
88 struct __uses_alloc<true, _Tp, _Alloc, _Args...>
90 is_constructible<_Tp, allocator_arg_t, const _Alloc&, _Args...>::value,
91 __uses_alloc1<_Alloc>,
92 __uses_alloc2<_Alloc>>::type
97 is_constructible<_Tp, allocator_arg_t, const _Alloc&, _Args...>,
98 is_constructible<_Tp, _Args..., const _Alloc&>>::value,
99 "construction with an allocator must be possible"
100 " if uses_allocator is true");
103 template<
typename _Tp,
typename _Alloc,
typename... _Args>
104 struct __uses_alloc<false, _Tp, _Alloc, _Args...>
107 template<
typename _Tp,
typename _Alloc,
typename... _Args>
108 using __uses_alloc_t =
109 __uses_alloc<uses_allocator<_Tp, _Alloc>::value, _Tp, _Alloc, _Args...>;
111 template<
typename _Tp,
typename _Alloc,
typename... _Args>
113 inline __uses_alloc_t<_Tp, _Alloc, _Args...>
114 __use_alloc(
const _Alloc& __a)
116 __uses_alloc_t<_Tp, _Alloc, _Args...> __ret;
121 template<
typename _Tp,
typename _Alloc,
typename... _Args>
123 __use_alloc(
const _Alloc&&) =
delete;
125 #if __cplusplus > 201402L
126 template <
typename _Tp,
typename _Alloc>
127 inline constexpr
bool uses_allocator_v =
128 uses_allocator<_Tp, _Alloc>::value;
131 template<
template<
typename...>
class _Predicate,
132 typename _Tp,
typename _Alloc,
typename... _Args>
133 struct __is_uses_allocator_predicate
134 : conditional<uses_allocator<_Tp, _Alloc>::value,
135 __or_<_Predicate<_Tp, allocator_arg_t, _Alloc, _Args...>,
136 _Predicate<_Tp, _Args..., _Alloc>>,
137 _Predicate<_Tp, _Args...>>::type { };
139 template<
typename _Tp,
typename _Alloc,
typename... _Args>
140 struct __is_uses_allocator_constructible
141 : __is_uses_allocator_predicate<is_constructible, _Tp, _Alloc, _Args...>
144 #if __cplusplus >= 201402L
145 template<
typename _Tp,
typename _Alloc,
typename... _Args>
146 _GLIBCXX17_INLINE constexpr
bool __is_uses_allocator_constructible_v =
147 __is_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
150 template<
typename _Tp,
typename _Alloc,
typename... _Args>
151 struct __is_nothrow_uses_allocator_constructible
152 : __is_uses_allocator_predicate<is_nothrow_constructible,
153 _Tp, _Alloc, _Args...>
157 #if __cplusplus >= 201402L
158 template<
typename _Tp,
typename _Alloc,
typename... _Args>
159 _GLIBCXX17_INLINE constexpr
bool
160 __is_nothrow_uses_allocator_constructible_v =
161 __is_nothrow_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
164 template<
typename _Tp,
typename... _Args>
165 void __uses_allocator_construct_impl(__uses_alloc0 __a, _Tp* __ptr,
167 { ::new ((
void*)__ptr) _Tp(std::forward<_Args>(__args)...); }
169 template<
typename _Tp,
typename _Alloc,
typename... _Args>
170 void __uses_allocator_construct_impl(__uses_alloc1<_Alloc> __a, _Tp* __ptr,
173 ::new ((
void*)__ptr) _Tp(allocator_arg, *__a._M_a,
174 std::forward<_Args>(__args)...);
177 template<
typename _Tp,
typename _Alloc,
typename... _Args>
178 void __uses_allocator_construct_impl(__uses_alloc2<_Alloc> __a, _Tp* __ptr,
180 { ::new ((
void*)__ptr) _Tp(std::forward<_Args>(__args)..., *__a._M_a); }
182 template<
typename _Tp,
typename _Alloc,
typename... _Args>
183 void __uses_allocator_construct(
const _Alloc& __a, _Tp* __ptr,
186 std::__uses_allocator_construct_impl(
187 std::__use_alloc<_Tp, _Alloc, _Args...>(__a), __ptr,
188 std::forward<_Args>(__args)...);
191 _GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
Declare uses_allocator so it can be specialized in <queue> etc.