25#ifndef _USES_ALLOCATOR_H
26#define _USES_ALLOCATOR_H 1
28#if __cplusplus < 201103L
35namespace std _GLIBCXX_VISIBILITY(default)
37_GLIBCXX_BEGIN_NAMESPACE_VERSION
41 struct __erased_type { };
46 template<
typename _Alloc,
typename _Tp>
47 using __is_erased_or_convertible
48 = __or_<is_convertible<_Alloc, _Tp>, is_same<_Tp, __erased_type>>;
51 struct allocator_arg_t {
explicit allocator_arg_t() =
default; };
53 _GLIBCXX17_INLINE
constexpr allocator_arg_t allocator_arg =
56 template<
typename _Tp,
typename _Alloc,
typename = __
void_t<>>
57 struct __uses_allocator_helper
60 template<
typename _Tp,
typename _Alloc>
61 struct __uses_allocator_helper<_Tp, _Alloc,
62 __void_t<typename _Tp::allocator_type>>
63 : __is_erased_or_convertible<_Alloc, typename _Tp::allocator_type>::type
67 template<
typename _Tp,
typename _Alloc>
69 : __uses_allocator_helper<_Tp, _Alloc>::type
72 struct __uses_alloc_base { };
74 struct __uses_alloc0 : __uses_alloc_base
76 struct _Sink {
void _GLIBCXX20_CONSTEXPR operator=(
const void*) { } } _M_a;
79 template<
typename _Alloc>
80 struct __uses_alloc1 : __uses_alloc_base {
const _Alloc* _M_a; };
82 template<
typename _Alloc>
83 struct __uses_alloc2 : __uses_alloc_base {
const _Alloc* _M_a; };
85 template<bool,
typename _Tp,
typename _Alloc,
typename... _Args>
88 template<
typename _Tp,
typename _Alloc,
typename... _Args>
89 struct __uses_alloc<true, _Tp, _Alloc, _Args...>
91 is_constructible<_Tp, allocator_arg_t, const _Alloc&, _Args...>::value,
92 __uses_alloc1<_Alloc>,
93 __uses_alloc2<_Alloc>>::type
98 is_constructible<_Tp, allocator_arg_t,
const _Alloc&, _Args...>,
99 is_constructible<_Tp, _Args...,
const _Alloc&>>::value,
100 "construction with an allocator must be possible"
101 " if uses_allocator is true");
104 template<
typename _Tp,
typename _Alloc,
typename... _Args>
105 struct __uses_alloc<false, _Tp, _Alloc, _Args...>
108 template<
typename _Tp,
typename _Alloc,
typename... _Args>
109 using __uses_alloc_t =
110 __uses_alloc<uses_allocator<_Tp, _Alloc>::value, _Tp, _Alloc, _Args...>;
112 template<
typename _Tp,
typename _Alloc,
typename... _Args>
114 inline __uses_alloc_t<_Tp, _Alloc, _Args...>
115 __use_alloc(
const _Alloc& __a)
117 __uses_alloc_t<_Tp, _Alloc, _Args...> __ret;
122 template<
typename _Tp,
typename _Alloc,
typename... _Args>
124 __use_alloc(
const _Alloc&&) =
delete;
126#if __cplusplus > 201402L
127 template <
typename _Tp,
typename _Alloc>
128 inline constexpr bool uses_allocator_v =
129 uses_allocator<_Tp, _Alloc>::value;
132 template<
template<
typename...>
class _Predicate,
133 typename _Tp,
typename _Alloc,
typename... _Args>
134 struct __is_uses_allocator_predicate
135 : conditional<uses_allocator<_Tp, _Alloc>::value,
136 __or_<_Predicate<_Tp, allocator_arg_t, _Alloc, _Args...>,
137 _Predicate<_Tp, _Args..., _Alloc>>,
138 _Predicate<_Tp, _Args...>>::type { };
140 template<
typename _Tp,
typename _Alloc,
typename... _Args>
141 struct __is_uses_allocator_constructible
142 : __is_uses_allocator_predicate<is_constructible, _Tp, _Alloc, _Args...>
145#if __cplusplus >= 201402L
146 template<
typename _Tp,
typename _Alloc,
typename... _Args>
147 _GLIBCXX17_INLINE
constexpr bool __is_uses_allocator_constructible_v =
148 __is_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
151 template<
typename _Tp,
typename _Alloc,
typename... _Args>
152 struct __is_nothrow_uses_allocator_constructible
153 : __is_uses_allocator_predicate<is_nothrow_constructible,
154 _Tp, _Alloc, _Args...>
158#if __cplusplus >= 201402L
159 template<
typename _Tp,
typename _Alloc,
typename... _Args>
160 _GLIBCXX17_INLINE
constexpr bool
161 __is_nothrow_uses_allocator_constructible_v =
162 __is_nothrow_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
165 template<
typename _Tp,
typename... _Args>
166 void __uses_allocator_construct_impl(__uses_alloc0 __a, _Tp* __ptr,
168 { ::new ((
void*)__ptr) _Tp(std::forward<_Args>(__args)...); }
170 template<
typename _Tp,
typename _Alloc,
typename... _Args>
171 void __uses_allocator_construct_impl(__uses_alloc1<_Alloc> __a, _Tp* __ptr,
174 ::new ((
void*)__ptr) _Tp(allocator_arg, *__a._M_a,
175 std::forward<_Args>(__args)...);
178 template<
typename _Tp,
typename _Alloc,
typename... _Args>
179 void __uses_allocator_construct_impl(__uses_alloc2<_Alloc> __a, _Tp* __ptr,
181 { ::new ((
void*)__ptr) _Tp(std::forward<_Args>(__args)..., *__a._M_a); }
183 template<
typename _Tp,
typename _Alloc,
typename... _Args>
184 void __uses_allocator_construct(
const _Alloc& __a, _Tp* __ptr,
187 std::__uses_allocator_construct_impl(
188 std::__use_alloc<_Tp, _Alloc, _Args...>(__a), __ptr,
189 std::forward<_Args>(__args)...);
193_GLIBCXX_END_NAMESPACE_VERSION
integral_constant< bool, 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.