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, const _Alloc&, _Args...>::value,
87 __uses_alloc1<_Alloc>,
88 __uses_alloc2<_Alloc>>::type
93 is_constructible<_Tp, allocator_arg_t, const _Alloc&, _Args...>,
94 is_constructible<_Tp, _Args..., const _Alloc&>>::value,
95 "construction with an allocator must be possible" 96 " if uses_allocator is true");
99 template<
typename _Tp,
typename _Alloc,
typename... _Args>
100 struct __uses_alloc<false, _Tp, _Alloc, _Args...>
103 template<
typename _Tp,
typename _Alloc,
typename... _Args>
104 using __uses_alloc_t =
105 __uses_alloc<uses_allocator<_Tp, _Alloc>::value, _Tp, _Alloc, _Args...>;
107 template<
typename _Tp,
typename _Alloc,
typename... _Args>
108 inline __uses_alloc_t<_Tp, _Alloc, _Args...>
109 __use_alloc(
const _Alloc& __a)
111 __uses_alloc_t<_Tp, _Alloc, _Args...> __ret;
116 template<
typename _Tp,
typename _Alloc,
typename... _Args>
118 __use_alloc(
const _Alloc&&) =
delete;
120 #if __cplusplus > 201402L 121 template <
typename _Tp,
typename _Alloc>
122 inline constexpr
bool uses_allocator_v =
123 uses_allocator<_Tp, _Alloc>::value;
126 template<
template<
typename...>
class _Predicate,
127 typename _Tp,
typename _Alloc,
typename... _Args>
128 struct __is_uses_allocator_predicate
129 : conditional<uses_allocator<_Tp, _Alloc>::value,
130 __or_<_Predicate<_Tp, allocator_arg_t, _Alloc, _Args...>,
131 _Predicate<_Tp, _Args..., _Alloc>>,
132 _Predicate<_Tp, _Args...>>::type { };
134 template<
typename _Tp,
typename _Alloc,
typename... _Args>
135 struct __is_uses_allocator_constructible
136 : __is_uses_allocator_predicate<is_constructible, _Tp, _Alloc, _Args...>
139 #if __cplusplus >= 201402L 140 template<
typename _Tp,
typename _Alloc,
typename... _Args>
141 _GLIBCXX17_INLINE constexpr
bool __is_uses_allocator_constructible_v =
142 __is_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
145 template<
typename _Tp,
typename _Alloc,
typename... _Args>
146 struct __is_nothrow_uses_allocator_constructible
147 : __is_uses_allocator_predicate<is_nothrow_constructible,
148 _Tp, _Alloc, _Args...>
152 #if __cplusplus >= 201402L 153 template<
typename _Tp,
typename _Alloc,
typename... _Args>
154 _GLIBCXX17_INLINE constexpr
bool 155 __is_nothrow_uses_allocator_constructible_v =
156 __is_nothrow_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
159 template<
typename _Tp,
typename... _Args>
160 void __uses_allocator_construct_impl(__uses_alloc0 __a, _Tp* __ptr,
162 { ::new ((
void*)__ptr) _Tp(std::forward<_Args>(__args)...); }
164 template<
typename _Tp,
typename _Alloc,
typename... _Args>
165 void __uses_allocator_construct_impl(__uses_alloc1<_Alloc> __a, _Tp* __ptr,
168 ::new ((
void*)__ptr) _Tp(allocator_arg, *__a._M_a,
169 std::forward<_Args>(__args)...);
172 template<
typename _Tp,
typename _Alloc,
typename... _Args>
173 void __uses_allocator_construct_impl(__uses_alloc2<_Alloc> __a, _Tp* __ptr,
175 { ::new ((
void*)__ptr) _Tp(std::forward<_Args>(__args)..., *__a._M_a); }
177 template<
typename _Tp,
typename _Alloc,
typename... _Args>
178 void __uses_allocator_construct(
const _Alloc& __a, _Tp* __ptr,
181 __uses_allocator_construct_impl(__use_alloc<_Tp, _Alloc, _Args...>(__a),
182 __ptr, std::forward<_Args>(__args)...);
185 _GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.