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
39 struct __erased_type { };
41 template<
typename _Alloc,
typename _Tp>
42 using __is_erased_or_convertible
43 = __or_<is_same<_Tp, __erased_type>, is_convertible<_Alloc, _Tp>>;
51 template<
typename _Tp,
typename _Alloc,
typename = __
void_t<>>
52 struct __uses_allocator_helper
55 template<
typename _Tp,
typename _Alloc>
56 struct __uses_allocator_helper<_Tp, _Alloc,
57 __void_t<typename _Tp::allocator_type>>
58 : __is_erased_or_convertible<_Alloc, typename _Tp::allocator_type>::type
62 template<
typename _Tp,
typename _Alloc>
64 : __uses_allocator_helper<_Tp, _Alloc>::type
67 struct __uses_alloc_base { };
69 struct __uses_alloc0 : __uses_alloc_base
71 struct _Sink {
void operator=(
const void*) { } } _M_a;
74 template<
typename _Alloc>
75 struct __uses_alloc1 : __uses_alloc_base {
const _Alloc* _M_a; };
77 template<
typename _Alloc>
78 struct __uses_alloc2 : __uses_alloc_base {
const _Alloc* _M_a; };
80 template<bool,
typename _Tp,
typename _Alloc,
typename... _Args>
83 template<
typename _Tp,
typename _Alloc,
typename... _Args>
84 struct __uses_alloc<true, _Tp, _Alloc, _Args...>
86 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value,
87 __uses_alloc1<_Alloc>,
88 __uses_alloc2<_Alloc>>::type
91 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>,
92 is_constructible<_Tp, _Args..., _Alloc>>::value,
"construction with" 93 " an allocator must be possible if uses_allocator is true");
96 template<
typename _Tp,
typename _Alloc,
typename... _Args>
97 struct __uses_alloc<false, _Tp, _Alloc, _Args...>
100 template<
typename _Tp,
typename _Alloc,
typename... _Args>
101 using __uses_alloc_t =
102 __uses_alloc<uses_allocator<_Tp, _Alloc>::value, _Tp, _Alloc, _Args...>;
104 template<
typename _Tp,
typename _Alloc,
typename... _Args>
105 inline __uses_alloc_t<_Tp, _Alloc, _Args...>
106 __use_alloc(
const _Alloc& __a)
108 __uses_alloc_t<_Tp, _Alloc, _Args...> __ret;
112 #if __cplusplus > 201402L 113 template <
typename _Tp,
typename _Alloc>
114 inline constexpr
bool uses_allocator_v =
118 template<
template<
typename...>
class _Predicate,
119 typename _Tp,
typename _Alloc,
typename... _Args>
120 struct __is_uses_allocator_predicate
121 : conditional<uses_allocator<_Tp, _Alloc>::value,
122 __or_<_Predicate<_Tp, allocator_arg_t, _Alloc, _Args...>,
123 _Predicate<_Tp, _Args..., _Alloc>>,
124 _Predicate<_Tp, _Args...>>::type { };
126 template<
typename _Tp,
typename _Alloc,
typename... _Args>
127 struct __is_uses_allocator_constructible
128 : __is_uses_allocator_predicate<is_constructible, _Tp, _Alloc, _Args...>
131 #if __cplusplus >= 201402L 132 template<
typename _Tp,
typename _Alloc,
typename... _Args>
133 _GLIBCXX17_INLINE constexpr
bool __is_uses_allocator_constructible_v =
134 __is_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
137 template<
typename _Tp,
typename _Alloc,
typename... _Args>
138 struct __is_nothrow_uses_allocator_constructible
139 : __is_uses_allocator_predicate<is_nothrow_constructible,
140 _Tp, _Alloc, _Args...>
144 #if __cplusplus >= 201402L 145 template<
typename _Tp,
typename _Alloc,
typename... _Args>
146 _GLIBCXX17_INLINE constexpr
bool 147 __is_nothrow_uses_allocator_constructible_v =
148 __is_nothrow_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
151 template<
typename _Tp,
typename... _Args>
152 void __uses_allocator_construct_impl(__uses_alloc0 __a, _Tp* __ptr,
154 { ::new ((
void*)__ptr) _Tp(std::forward<_Args>(__args)...); }
156 template<
typename _Tp,
typename _Alloc,
typename... _Args>
157 void __uses_allocator_construct_impl(__uses_alloc1<_Alloc> __a, _Tp* __ptr,
160 ::new ((
void*)__ptr) _Tp(allocator_arg, *__a._M_a,
161 std::forward<_Args>(__args)...);
164 template<
typename _Tp,
typename _Alloc,
typename... _Args>
165 void __uses_allocator_construct_impl(__uses_alloc2<_Alloc> __a, _Tp* __ptr,
167 { ::new ((
void*)__ptr) _Tp(std::forward<_Args>(__args)..., *__a._M_a); }
169 template<
typename _Tp,
typename _Alloc,
typename... _Args>
170 void __uses_allocator_construct(
const _Alloc& __a, _Tp* __ptr,
173 __uses_allocator_construct_impl(__use_alloc<_Tp, _Alloc, _Args...>(__a),
174 __ptr, std::forward<_Args>(__args)...);
177 _GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Declare uses_allocator so it can be specialized in <queue> etc.