30 #ifndef _ALLOC_TRAITS_H
31 #define _ALLOC_TRAITS_H 1
33 #ifdef __GXX_EXPERIMENTAL_CXX0X__
38 namespace std _GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
42 template<
typename _Alloc,
typename _Tp>
43 class __alloctr_rebind_helper
45 template<
typename _Alloc2,
typename _Tp2>
47 _S_chk(
typename _Alloc2::template rebind<_Tp2>::other*)
50 template<
typename,
typename>
56 static const bool __value = _S_chk<_Alloc, _Tp>(
nullptr);
59 template<
typename _Alloc,
typename _Tp,
60 bool = __alloctr_rebind_helper<_Alloc, _Tp>::__value>
61 struct __alloctr_rebind;
63 template<
typename _Alloc,
typename _Tp>
64 struct __alloctr_rebind<_Alloc, _Tp, true>
66 typedef typename _Alloc::template rebind<_Tp>::other __type;
69 template<
template<
typename,
typename...>
class _Alloc,
typename _Tp,
70 typename _Up,
typename... _Args>
71 struct __alloctr_rebind<_Alloc<_Up, _Args...>, _Tp, false>
73 typedef _Alloc<_Tp, _Args...> __type;
80 template<
typename _Alloc>
88 #define _GLIBCXX_ALLOC_TR_NESTED_TYPE(_NTYPE, _ALT) \
90 template<typename _Tp> \
91 static typename _Tp::_NTYPE _S_##_NTYPE##_helper(_Tp*); \
92 static _ALT _S_##_NTYPE##_helper(...); \
93 typedef decltype(_S_##_NTYPE##_helper((_Alloc*)0)) __##_NTYPE; \
114 typedef __const_pointer const_pointer;
125 typedef __void_pointer void_pointer;
136 typedef __const_void_pointer const_void_pointer;
147 typedef __difference_type difference_type;
158 typedef __size_type size_type;
169 typedef __propagate_on_container_copy_assignment
170 propagate_on_container_copy_assignment;
181 typedef __propagate_on_container_move_assignment
182 propagate_on_container_move_assignment;
193 typedef __propagate_on_container_swap propagate_on_container_swap;
195 #undef _GLIBCXX_ALLOC_TR_NESTED_TYPE
197 template<
typename _Tp>
198 using rebind_alloc =
typename __alloctr_rebind<_Alloc, _Tp>::__type;
199 template<
typename _Tp>
203 template<
typename _Alloc2>
204 struct __allocate_helper
206 template<
typename _Alloc3,
207 typename = decltype(std::declval<_Alloc3*>()->
allocate(
208 std::declval<size_type>(),
209 std::declval<const_void_pointer>()))>
215 typedef decltype(__test<_Alloc>(0)) type;
216 static const bool value = type::value;
219 template<
typename _Alloc2>
222 _S_allocate(_Alloc2& __a, size_type __n, const_void_pointer __hint)
223 {
return __a.allocate(__n, __hint); }
225 template<
typename _Alloc2>
227 enable_if<!__allocate_helper<_Alloc2>::value, pointer>::type
228 _S_allocate(_Alloc2& __a, size_type __n, ...)
229 {
return __a.allocate(__n); }
231 template<
typename _Tp,
typename... _Args>
232 struct __construct_helper
234 template<
typename _Alloc2,
235 typename = decltype(std::declval<_Alloc2*>()->
construct(
236 std::declval<_Tp*>(), std::declval<_Args>()...))>
242 typedef decltype(__test<_Alloc>(0)) type;
243 static const
bool value = type::value;
246 template<typename _Tp, typename... _Args>
248 enable_if<__construct_helper<_Tp, _Args...>::value,
void>::type
249 _S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
250 { __a.construct(__p, std::forward<_Args>(__args)...); }
252 template<
typename _Tp,
typename... _Args>
254 enable_if<!__construct_helper<_Tp, _Args...>::value,
void>::type
255 _S_construct(_Alloc&, _Tp* __p, _Args&&... __args)
256 { ::new((
void*)__p) _Tp(std::
forward<_Args>(__args)...); }
258 template<typename _Tp>
259 struct __destroy_helper
261 template<
typename _Alloc2,
262 typename = decltype(std::declval<_Alloc2*>()->
destroy(
263 std::declval<_Tp*>()))>
269 typedef decltype(__test<_Alloc>(0)) type;
270 static const
bool value = type::value;
273 template<typename _Tp>
274 static typename enable_if<__destroy_helper<_Tp>::value,
void>::type
275 _S_destroy(_Alloc& __a, _Tp* __p)
276 { __a.destroy(__p); }
278 template<
typename _Tp>
279 static typename enable_if<!__destroy_helper<_Tp>::value,
void>::type
280 _S_destroy(_Alloc&, _Tp* __p)
283 template<
typename _Alloc2>
284 struct __maxsize_helper
286 template<
typename _Alloc3,
287 typename = decltype(std::declval<_Alloc3*>()->
max_size())>
293 typedef decltype(__test<_Alloc2>(0)) type;
294 static const
bool value = type::value;
297 template<typename _Alloc2>
299 enable_if<__maxsize_helper<_Alloc2>::value, size_type>::type
300 _S_max_size(_Alloc2& __a)
301 {
return __a.max_size(); }
303 template<
typename _Alloc2>
305 enable_if<!__maxsize_helper<_Alloc2>::value, size_type>::type
306 _S_max_size(_Alloc2&)
307 {
return __gnu_cxx::__numeric_traits<size_type>::__max; }
309 template<
typename _Alloc2>
310 struct __select_helper
312 template<
typename _Alloc3,
typename
313 = decltype(std::declval<_Alloc3*>()
320 typedef decltype(__test<_Alloc2>(0)) type;
321 static const
bool value = type::value;
323 template<typename _Alloc2>
325 enable_if<__select_helper<_Alloc2>::value, _Alloc2>::type
326 _S_select(_Alloc2& __a)
327 {
return __a.select_on_container_copy_construction(); }
329 template<
typename _Alloc2>
331 enable_if<!__select_helper<_Alloc2>::value, _Alloc2>::type
332 _S_select(_Alloc2& __a)
346 {
return __a.allocate(__n); }
360 allocate(_Alloc& __a, size_type __n, const_void_pointer __hint)
361 {
return _S_allocate(__a, __n, __hint); }
371 static void deallocate(_Alloc& __a, pointer __p, size_type __n)
372 { __a.deallocate(__p, __n); }
385 template<
typename _Tp,
typename... _Args>
386 static void construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
387 { _S_construct(__a, __p, std::forward<_Args>(__args)...); }
399 { _S_destroy(__a, __p); }
410 {
return _S_max_size(__a); }
422 {
return _S_select(__rhs); }
425 template<
typename _Alloc>
427 __do_alloc_on_copy(_Alloc& __one,
const _Alloc& __two,
true_type)
430 template<
typename _Alloc>
432 __do_alloc_on_copy(_Alloc&,
const _Alloc&,
false_type)
435 template<
typename _Alloc>
436 inline void __alloc_on_copy(_Alloc& __one,
const _Alloc& __two)
438 typedef allocator_traits<_Alloc> __traits;
439 typedef typename __traits::propagate_on_container_copy_assignment __pocca;
440 __do_alloc_on_copy(__one, __two, __pocca());
443 template<
typename _Alloc>
444 inline _Alloc __alloc_on_copy(
const _Alloc& __a)
446 typedef allocator_traits<_Alloc> __traits;
450 template<
typename _Alloc>
451 inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two,
true_type)
452 { __one = std::move(__two); }
454 template<
typename _Alloc>
455 inline void __do_alloc_on_move(_Alloc&, _Alloc&,
false_type)
458 template<
typename _Alloc>
459 inline void __alloc_on_move(_Alloc& __one, _Alloc& __two)
461 typedef allocator_traits<_Alloc> __traits;
462 typedef typename __traits::propagate_on_container_move_assignment __pocma;
463 __do_alloc_on_move(__one, __two, __pocma());
466 template<
typename _Alloc>
467 inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two,
true_type)
473 template<
typename _Alloc>
474 inline void __do_alloc_on_swap(_Alloc&, _Alloc&,
false_type)
477 template<
typename _Alloc>
478 inline void __alloc_on_swap(_Alloc& __one, _Alloc& __two)
480 typedef allocator_traits<_Alloc> __traits;
481 typedef typename __traits::propagate_on_container_swap __pocs;
482 __do_alloc_on_swap(__one, __two, __pocs());
485 _GLIBCXX_END_NAMESPACE_VERSION