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
53 = __or_<is_convertible<_Alloc, _Tp>, is_same<_Tp, __erased_type>>;
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 =
134 uses_allocator<_Tp, _Alloc>::value;
137 template<
template<
typename...>
class _Predicate,
138 typename _Tp,
typename _Alloc,
typename... _Args>
139 struct __is_uses_allocator_predicate
140 : __conditional_t<uses_allocator<_Tp, _Alloc>::value,
141 __or_<_Predicate<_Tp, allocator_arg_t, _Alloc, _Args...>,
142 _Predicate<_Tp, _Args..., _Alloc>>,
143 _Predicate<_Tp, _Args...>> { };
145 template<
typename _Tp,
typename _Alloc,
typename... _Args>
146 struct __is_uses_allocator_constructible
147 : __is_uses_allocator_predicate<is_constructible, _Tp, _Alloc, _Args...>
150#if __cplusplus >= 201402L
151 template<
typename _Tp,
typename _Alloc,
typename... _Args>
152 _GLIBCXX17_INLINE
constexpr bool __is_uses_allocator_constructible_v =
153 __is_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
156 template<
typename _Tp,
typename _Alloc,
typename... _Args>
157 struct __is_nothrow_uses_allocator_constructible
158 : __is_uses_allocator_predicate<is_nothrow_constructible,
159 _Tp, _Alloc, _Args...>
163#if __cplusplus >= 201402L
164 template<
typename _Tp,
typename _Alloc,
typename... _Args>
165 _GLIBCXX17_INLINE
constexpr bool
166 __is_nothrow_uses_allocator_constructible_v =
167 __is_nothrow_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
170 template<
typename _Tp,
typename... _Args>
171 void __uses_allocator_construct_impl(__uses_alloc0, _Tp* __ptr,
173 { ::new ((
void*)__ptr) _Tp(std::forward<_Args>(__args)...); }
175 template<
typename _Tp,
typename _Alloc,
typename... _Args>
176 void __uses_allocator_construct_impl(__uses_alloc1<_Alloc> __a, _Tp* __ptr,
179 ::new ((
void*)__ptr) _Tp(allocator_arg, *__a._M_a,
180 std::forward<_Args>(__args)...);
183 template<
typename _Tp,
typename _Alloc,
typename... _Args>
184 void __uses_allocator_construct_impl(__uses_alloc2<_Alloc> __a, _Tp* __ptr,
186 { ::new ((
void*)__ptr) _Tp(std::forward<_Args>(__args)..., *__a._M_a); }
188 template<
typename _Tp,
typename _Alloc,
typename... _Args>
189 void __uses_allocator_construct(
const _Alloc& __a, _Tp* __ptr,
192 std::__uses_allocator_construct_impl(
193 std::__use_alloc<_Tp, _Alloc, _Args...>(__a), __ptr,
194 std::forward<_Args>(__args)...);
198_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.
ISO C++ entities toplevel namespace is std.