30 #ifndef _ALLOC_TRAITS_H    31 #define _ALLOC_TRAITS_H 1    33 #if __cplusplus >= 201103L    39 namespace std _GLIBCXX_VISIBILITY(default)
    41 _GLIBCXX_BEGIN_NAMESPACE_VERSION
    43   template<
typename _Alloc, 
typename _Tp>
    44     class __alloctr_rebind_helper
    46       template<
typename _Alloc2, 
typename _Tp2>
    48         _S_chk(
typename _Alloc2::template rebind<_Tp2>::other*);
    50       template<
typename, 
typename>
    55       using __type = decltype(_S_chk<_Alloc, _Tp>(
nullptr));
    58   template<
typename _Alloc, 
typename _Tp,
    59            bool = __alloctr_rebind_helper<_Alloc, _Tp>::__type::value>
    60     struct __alloctr_rebind;
    62   template<
typename _Alloc, 
typename _Tp>
    63     struct __alloctr_rebind<_Alloc, _Tp, true>
    65       typedef typename _Alloc::template rebind<_Tp>::other __type;
    68   template<
template<
typename, 
typename...> 
class _Alloc, 
typename _Tp,
    69            typename _Up, 
typename... _Args>
    70     struct __alloctr_rebind<_Alloc<_Up, _Args...>, _Tp, false>
    72       typedef _Alloc<_Tp, _Args...> __type;
    75   template<
typename _Alloc, 
typename _Tp>
    76     using __alloc_rebind = 
typename __alloctr_rebind<_Alloc, _Tp>::__type;
    82   template<
typename _Alloc>
    90 #define _GLIBCXX_ALLOC_TR_NESTED_TYPE(_NTYPE, _ALT) \    92   template<typename _Tp> \    93     static typename _Tp::_NTYPE _S_##_NTYPE##_helper(_Tp*); \    94   static _ALT _S_##_NTYPE##_helper(...); \    95     typedef decltype(_S_##_NTYPE##_helper((_Alloc*)0)) __##_NTYPE; \    98 _GLIBCXX_ALLOC_TR_NESTED_TYPE(
pointer, value_type*)
   108   typename 
pointer_traits<pointer>::template rebind<const value_type>)
   116       typedef __const_pointer const_pointer;
   127       typedef __void_pointer void_pointer;
   138       typedef __const_void_pointer const_void_pointer;
   149       typedef __difference_type difference_type;
   152                               typename make_unsigned<difference_type>::type)
   160       typedef __size_type size_type;
   171       typedef __propagate_on_container_copy_assignment
   172         propagate_on_container_copy_assignment;
   183       typedef __propagate_on_container_move_assignment
   184         propagate_on_container_move_assignment;
   195       typedef __propagate_on_container_swap propagate_on_container_swap;
   197 #undef _GLIBCXX_ALLOC_TR_NESTED_TYPE   199       template<
typename _Tp>
   200         using rebind_alloc = 
typename __alloctr_rebind<_Alloc, _Tp>::__type;
   201       template<
typename _Tp>
   205       template<
typename _Alloc2>
   206         struct __allocate_helper
   208           template<
typename _Alloc3,
   209             typename = decltype(std::declval<_Alloc3*>()->allocate(
   210                   std::declval<size_type>(),
   211                   std::declval<const_void_pointer>()))>
   217           using type = decltype(__test<_Alloc>(0));
   220       template<
typename _Alloc2>
   221         using __has_allocate = 
typename __allocate_helper<_Alloc2>::type;
   223       template<
typename _Alloc2,
   224                typename = _Require<__has_allocate<_Alloc2>>>
   226         _S_allocate(_Alloc2& __a, size_type __n, const_void_pointer __hint)
   227         { 
return __a.allocate(__n, __hint); }
   229       template<
typename _Alloc2, 
typename _UnusedHint,
   230                typename = _Require<__not_<__has_allocate<_Alloc2>>>>
   232         _S_allocate(_Alloc2& __a, size_type __n, _UnusedHint)
   233         { 
return __a.allocate(__n); }
   235       template<
typename _Tp, 
typename... _Args>
   236         struct __construct_helper
   238           template<
typename _Alloc2,
   239             typename = decltype(std::declval<_Alloc2*>()->construct(
   240                   std::declval<_Tp*>(), std::declval<_Args>()...))>
   246           using type = decltype(__test<_Alloc>(0));
   249       template<
typename _Tp, 
typename... _Args>
   250         using __has_construct
   251           = 
typename __construct_helper<_Tp, _Args...>::type;
   253       template<
typename _Tp, 
typename... _Args>
   254         static _Require<__has_construct<_Tp, _Args...>>
   255         _S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
   256         { __a.construct(__p, std::forward<_Args>(__args)...); }
   258       template<
typename _Tp, 
typename... _Args>
   260         _Require<__and_<__not_<__has_construct<_Tp, _Args...>>,
   261                                is_constructible<_Tp, _Args...>>>
   262         _S_construct(_Alloc&, _Tp* __p, _Args&&... __args)
   263         { ::new((
void*)__p) _Tp(std::forward<_Args>(__args)...); }
   265       template<
typename _Tp>
   266         struct __destroy_helper
   268           template<
typename _Alloc2,
   269             typename = decltype(std::declval<_Alloc2*>()->destroy(
   270                   std::declval<_Tp*>()))>
   276           using type = decltype(__test<_Alloc>(0));
   279       template<
typename _Tp>
   280         using __has_destroy = 
typename __destroy_helper<_Tp>::type;
   282       template<
typename _Tp>
   283         static _Require<__has_destroy<_Tp>>
   284         _S_destroy(_Alloc& __a, _Tp* __p)
   285         { __a.destroy(__p); }
   287       template<
typename _Tp>
   288         static _Require<__not_<__has_destroy<_Tp>>>
   289         _S_destroy(_Alloc&, _Tp* __p)
   292       template<
typename _Alloc2>
   293         struct __maxsize_helper
   295           template<
typename _Alloc3,
   296             typename = decltype(std::declval<_Alloc3*>()->max_size())>
   302           using type = decltype(__test<_Alloc2>(0));
   305       template<
typename _Alloc2>
   306         using __has_max_size = 
typename __maxsize_helper<_Alloc2>::type;
   308       template<
typename _Alloc2,
   309                typename = _Require<__has_max_size<_Alloc2>>>
   311         _S_max_size(_Alloc2& __a, 
int)
   312         { 
return __a.max_size(); }
   314       template<
typename _Alloc2,
   315                typename = _Require<__not_<__has_max_size<_Alloc2>>>>
   317         _S_max_size(_Alloc2&, ...)
   318         { 
return __gnu_cxx::__numeric_traits<size_type>::__max; }
   320       template<
typename _Alloc2>
   321         struct __select_helper
   323           template<
typename _Alloc3, 
typename   324             = decltype(std::declval<_Alloc3*>()
   325                 ->select_on_container_copy_construction())>
   331           using type = decltype(__test<_Alloc2>(0));
   334       template<
typename _Alloc2>
   335         using __has_soccc = 
typename __select_helper<_Alloc2>::type;
   337       template<
typename _Alloc2,
   338                typename = _Require<__has_soccc<_Alloc2>>>
   340         _S_select(_Alloc2& __a, 
int)
   341         { 
return __a.select_on_container_copy_construction(); }
   343       template<
typename _Alloc2,
   344                typename = _Require<__not_<__has_soccc<_Alloc2>>>>
   346         _S_select(_Alloc2& __a, ...)
   360       { 
return __a.allocate(__n); }
   374       allocate(_Alloc& __a, size_type __n, const_void_pointer __hint)
   375       { 
return _S_allocate(__a, __n, __hint); }
   385       static void deallocate(_Alloc& __a, pointer __p, size_type __n)
   386       { __a.deallocate(__p, __n); }
   399       template<
typename _Tp, 
typename... _Args>
   400         static auto construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
   401         -> decltype(_S_construct(__a, __p, std::forward<_Args>(__args)...))
   402         { _S_construct(__a, __p, std::forward<_Args>(__args)...); }
   412       template<
typename _Tp>
   414         { _S_destroy(__a, __p); }
   424       static size_type 
max_size(
const _Alloc& __a) noexcept
   425       { 
return _S_max_size(__a, 0); }
   437       { 
return _S_select(__rhs, 0); }
   441   template<
typename _Tp>
   447       using value_type = _Tp;
   450       using pointer = _Tp*;
   453       using const_pointer = 
const _Tp*;
   456       using void_pointer = 
void*;
   459       using const_void_pointer = 
const void*;
   462       using difference_type = std::ptrdiff_t;
   465       using size_type = std::size_t;
   471       using propagate_on_container_move_assignment = 
true_type;
   476       template<
typename _Up>
   479       template<
typename _Up>
   491       { 
return __a.allocate(__n); }
   504       allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
   505       { 
return __a.allocate(__n, __hint); }
   517       { __a.deallocate(__p, __n); }
   527       template<
typename _Up, 
typename... _Args>
   529         construct(allocator_type& __a, _Up* __p, _Args&&... __args)
   530         { __a.construct(__p, std::forward<_Args>(__args)...); }
   539       template<
typename _Up>
   542         { __a.destroy(__p); }
   551       { 
return __a.max_size(); }
   558       static allocator_type
   564   template<
typename _Alloc>
   566     __do_alloc_on_copy(_Alloc& __one, 
const _Alloc& __two, 
true_type)
   569   template<
typename _Alloc>
   571     __do_alloc_on_copy(_Alloc&, 
const _Alloc&, 
false_type)
   574   template<
typename _Alloc>
   575     inline void __alloc_on_copy(_Alloc& __one, 
const _Alloc& __two)
   578       typedef typename __traits::propagate_on_container_copy_assignment __pocca;
   579       __do_alloc_on_copy(__one, __two, __pocca());
   582   template<
typename _Alloc>
   583     inline _Alloc __alloc_on_copy(
const _Alloc& __a)
   586       return __traits::select_on_container_copy_construction(__a);
   589   template<
typename _Alloc>
   590     inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two, 
true_type)
   591     { __one = std::move(__two); }
   593   template<
typename _Alloc>
   594     inline void __do_alloc_on_move(_Alloc&, _Alloc&, 
false_type)
   597   template<
typename _Alloc>
   598     inline void __alloc_on_move(_Alloc& __one, _Alloc& __two)
   601       typedef typename __traits::propagate_on_container_move_assignment __pocma;
   602       __do_alloc_on_move(__one, __two, __pocma());
   605   template<
typename _Alloc>
   606     inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two, 
true_type)
   612   template<
typename _Alloc>
   613     inline void __do_alloc_on_swap(_Alloc&, _Alloc&, 
false_type)
   616   template<
typename _Alloc>
   617     inline void __alloc_on_swap(_Alloc& __one, _Alloc& __two)
   620       typedef typename __traits::propagate_on_container_swap __pocs;
   621       __do_alloc_on_swap(__one, __two, __pocs());
   624   template<
typename _Alloc>
   625     class __is_copy_insertable_impl
   629       template<
typename _Up, 
typename   630                = decltype(_Traits::construct(std::declval<_Alloc&>(),
   631                                              std::declval<_Up*>(),
   632                                              std::declval<const _Up&>()))>
   636       template<
typename _Up>
   641       typedef decltype(_M_select<typename _Alloc::value_type>(0)) type;
   645   template<
typename _Alloc>
   646     struct __is_copy_insertable
   647     : __is_copy_insertable_impl<_Alloc>::type
   651   template<
typename _Tp>
   652     struct __is_copy_insertable<allocator<_Tp>>
   653     : is_copy_constructible<_Tp>
   656 _GLIBCXX_END_NAMESPACE_VERSION
 _Alloc::value_type value_type
The allocated type. 
__void_pointer void_pointer
The allocator's void pointer type. 
Uniform interface to all allocator types. 
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value. 
static pointer allocate(allocator_type &__a, size_type __n, const_void_pointer __hint)
Allocate memory. 
__propagate_on_container_swap propagate_on_container_swap
How the allocator is propagated on swap. 
__propagate_on_container_move_assignment propagate_on_container_move_assignment
How the allocator is propagated on move assignment. 
__const_void_pointer const_void_pointer
The allocator's const void pointer type. 
The standard allocator, as per [20.4]. 
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory. 
static pointer allocate(_Alloc &__a, size_type __n)
Allocate memory. 
static pointer allocate(allocator_type &__a, size_type __n)
Allocate memory. 
static void construct(allocator_type &__a, _Up *__p, _Args &&...__args)
Construct an object of type _Up. 
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value. 
_Alloc allocator_type
The allocator type. 
__const_pointer const_pointer
The allocator's const pointer type. 
static size_type max_size(const allocator_type &__a) noexcept
The maximum supported allocation size. 
Uniform interface to all pointer-like types. 
static auto construct(_Alloc &__a, _Tp *__p, _Args &&...__args) -> decltype(_S_construct(__a, __p, std::forward< _Args >(__args)...))
Construct an object of type _Tp. 
static void destroy(_Alloc &__a, _Tp *__p)
Destroy an object of type _Tp. 
static void deallocate(allocator_type &__a, pointer __p, size_type __n)
Deallocate memory. 
static allocator_type select_on_container_copy_construction(const allocator_type &__rhs)
Obtain an allocator to use when copying a container. 
static void destroy(allocator_type &__a, _Up *__p)
Destroy an object of type _Up. 
__size_type size_type
The allocator's size type. 
__pointer pointer
The allocator's pointer type. 
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size. 
__propagate_on_container_copy_assignment propagate_on_container_copy_assignment
How the allocator is propagated on copy assignment. 
static _Alloc select_on_container_copy_construction(const _Alloc &__rhs)
Obtain an allocator to use when copying a container. 
ISO C++ entities toplevel namespace is std. 
__difference_type difference_type
The allocator's difference type. 
static pointer allocate(_Alloc &__a, size_type __n, const_void_pointer __hint)
Allocate memory.