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 const bool __alloctr_rebind_helper<_Alloc, _Tp>::__value;
62 template<
typename _Alloc,
typename _Tp,
63 bool = __alloctr_rebind_helper<_Alloc, _Tp>::__value>
64 struct __alloctr_rebind;
66 template<
typename _Alloc,
typename _Tp>
67 struct __alloctr_rebind<_Alloc, _Tp, true>
69 typedef typename _Alloc::template rebind<_Tp>::other __type;
72 template<
template<
typename,
typename...>
class _Alloc,
typename _Tp,
73 typename _Up,
typename... _Args>
74 struct __alloctr_rebind<_Alloc<_Up, _Args...>, _Tp, false>
76 typedef _Alloc<_Tp, _Args...> __type;
83 template<
typename _Alloc>
91 #define _GLIBCXX_ALLOC_TR_NESTED_TYPE(_NTYPE, _ALT) \
93 template<typename _Tp> \
94 static typename _Tp::_NTYPE _S_##_NTYPE##_helper(_Tp*); \
95 static _ALT _S_##_NTYPE##_helper(...); \
96 typedef decltype(_S_##_NTYPE##_helper((_Alloc*)0)) __##_NTYPE; \
117 typedef __const_pointer const_pointer;
128 typedef __void_pointer void_pointer;
139 typedef __const_void_pointer const_void_pointer;
150 typedef __difference_type difference_type;
161 typedef __size_type size_type;
172 typedef __propagate_on_container_copy_assignment
173 propagate_on_container_copy_assignment;
184 typedef __propagate_on_container_move_assignment
185 propagate_on_container_move_assignment;
196 typedef __propagate_on_container_swap propagate_on_container_swap;
198 #undef _GLIBCXX_ALLOC_TR_NESTED_TYPE
200 template<
typename _Tp>
201 using rebind_alloc =
typename __alloctr_rebind<_Alloc, _Tp>::__type;
202 template<
typename _Tp>
206 template<
typename _Alloc2>
207 struct __allocate_helper
209 template<
typename _Alloc3,
210 typename = decltype(std::declval<_Alloc3*>()->
allocate(
211 std::declval<size_type>(),
212 std::declval<const_void_pointer>()))>
218 typedef decltype(__test<_Alloc>(0)) type;
219 static const bool value = type::value;
222 template<
typename _Alloc2>
225 _S_allocate(_Alloc2& __a, size_type __n, const_void_pointer __hint)
226 {
return __a.allocate(__n, __hint); }
228 template<
typename _Alloc2>
230 enable_if<!__allocate_helper<_Alloc2>::value, pointer>::type
231 _S_allocate(_Alloc2& __a, size_type __n, ...)
232 {
return __a.allocate(__n); }
234 template<
typename _Tp,
typename... _Args>
235 struct __construct_helper
237 template<
typename _Alloc2,
238 typename = decltype(std::declval<_Alloc2*>()->
construct(
239 std::declval<_Tp*>(), std::declval<_Args>()...))>
245 typedef decltype(__test<_Alloc>(0)) type;
246 static const
bool value = type::value;
249 template<typename _Tp, typename... _Args>
251 enable_if<__construct_helper<_Tp, _Args...>::value,
void>::type
252 _S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
253 { __a.construct(__p, std::forward<_Args>(__args)...); }
255 template<
typename _Tp,
typename... _Args>
257 enable_if<!__construct_helper<_Tp, _Args...>::value,
void>::type
258 _S_construct(_Alloc&, _Tp* __p, _Args&&... __args)
259 { ::new((
void*)__p) _Tp(std::
forward<_Args>(__args)...); }
261 template<typename _Tp>
262 struct __destroy_helper
264 template<
typename _Alloc2,
265 typename = decltype(std::declval<_Alloc2*>()->
destroy(
266 std::declval<_Tp*>()))>
272 typedef decltype(__test<_Alloc>(0)) type;
273 static const
bool value = type::value;
276 template<typename _Tp>
277 static typename enable_if<__destroy_helper<_Tp>::value,
void>::type
278 _S_destroy(_Alloc& __a, _Tp* __p)
279 { __a.destroy(__p); }
281 template<
typename _Tp>
282 static typename enable_if<!__destroy_helper<_Tp>::value,
void>::type
283 _S_destroy(_Alloc&, _Tp* __p)
286 template<
typename _Alloc2>
287 struct __maxsize_helper
289 template<
typename _Alloc3,
290 typename = decltype(std::declval<_Alloc3*>()->
max_size())>
296 typedef decltype(__test<_Alloc2>(0)) type;
297 static const
bool value = type::value;
300 template<typename _Alloc2>
302 enable_if<__maxsize_helper<_Alloc2>::value, size_type>::type
303 _S_max_size(_Alloc2& __a)
304 {
return __a.max_size(); }
306 template<
typename _Alloc2>
308 enable_if<!__maxsize_helper<_Alloc2>::value, size_type>::type
309 _S_max_size(_Alloc2&)
310 {
return __gnu_cxx::__numeric_traits<size_type>::__max; }
312 template<
typename _Alloc2>
313 struct __select_helper
315 template<
typename _Alloc3,
typename
316 = decltype(std::declval<_Alloc3*>()
323 typedef decltype(__test<_Alloc2>(0)) type;
324 static const
bool value = type::value;
326 template<typename _Alloc2>
328 enable_if<__select_helper<_Alloc2>::value, _Alloc2>::type
329 _S_select(_Alloc2& __a)
330 {
return __a.select_on_container_copy_construction(); }
332 template<
typename _Alloc2>
334 enable_if<!__select_helper<_Alloc2>::value, _Alloc2>::type
335 _S_select(_Alloc2& __a)
349 {
return __a.allocate(__n); }
363 allocate(_Alloc& __a, size_type __n, const_void_pointer __hint)
364 {
return _S_allocate(__a, __n, __hint); }
374 static void deallocate(_Alloc& __a, pointer __p, size_type __n)
375 { __a.deallocate(__p, __n); }
388 template<
typename _Tp,
typename... _Args>
389 static void construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
390 { _S_construct(__a, __p, std::forward<_Args>(__args)...); }
402 { _S_destroy(__a, __p); }
413 {
return _S_max_size(__a); }
425 {
return _S_select(__rhs); }
428 template<
typename _Alloc>
429 template<
typename _Alloc2>
430 const bool allocator_traits<_Alloc>::__allocate_helper<_Alloc2>::value;
432 template<
typename _Alloc>
433 template<
typename _Tp,
typename... _Args>
435 allocator_traits<_Alloc>::__construct_helper<_Tp, _Args...>::value;
437 template<
typename _Alloc>
438 template<
typename _Tp>
439 const bool allocator_traits<_Alloc>::__destroy_helper<_Tp>::value;
441 template<
typename _Alloc>
442 template<
typename _Alloc2>
443 const bool allocator_traits<_Alloc>::__maxsize_helper<_Alloc2>::value;
445 template<
typename _Alloc>
446 template<
typename _Alloc2>
447 const bool allocator_traits<_Alloc>::__select_helper<_Alloc2>::value;
449 template<
typename _Alloc>
451 __do_alloc_on_copy(_Alloc& __one,
const _Alloc& __two,
true_type)
454 template<
typename _Alloc>
456 __do_alloc_on_copy(_Alloc&,
const _Alloc&,
false_type)
459 template<
typename _Alloc>
460 inline void __alloc_on_copy(_Alloc& __one,
const _Alloc& __two)
462 typedef allocator_traits<_Alloc> __traits;
463 typedef typename __traits::propagate_on_container_copy_assignment __pocca;
464 __do_alloc_on_copy(__one, __two, __pocca());
467 template<
typename _Alloc>
468 inline _Alloc __alloc_on_copy(
const _Alloc& __a)
470 typedef allocator_traits<_Alloc> __traits;
471 return __traits::select_on_container_copy_construction(__a);
474 template<
typename _Alloc>
475 inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two,
true_type)
476 { __one = std::move(__two); }
478 template<
typename _Alloc>
479 inline void __do_alloc_on_move(_Alloc&, _Alloc&,
false_type)
482 template<
typename _Alloc>
483 inline void __alloc_on_move(_Alloc& __one, _Alloc& __two)
485 typedef allocator_traits<_Alloc> __traits;
486 typedef typename __traits::propagate_on_container_move_assignment __pocma;
487 __do_alloc_on_move(__one, __two, __pocma());
490 template<
typename _Alloc>
491 inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two,
true_type)
497 template<
typename _Alloc>
498 inline void __do_alloc_on_swap(_Alloc&, _Alloc&,
false_type)
501 template<
typename _Alloc>
502 inline void __alloc_on_swap(_Alloc& __one, _Alloc& __two)
504 typedef allocator_traits<_Alloc> __traits;
505 typedef typename __traits::propagate_on_container_swap __pocs;
506 __do_alloc_on_swap(__one, __two, __pocs());
509 _GLIBCXX_END_NAMESPACE_VERSION