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 _Tp>
45 template<
typename _Alloc,
typename _Tp>
46 class __alloctr_rebind_helper
48 template<
typename _Alloc2,
typename _Tp2>
53 template<
typename,
typename>
59 static const bool __value = _S_chk<_Alloc, _Tp>(
nullptr);
62 template<
typename _Alloc,
typename _Tp>
63 const bool __alloctr_rebind_helper<_Alloc, _Tp>::__value;
65 template<
typename _Alloc,
typename _Tp,
66 bool = __alloctr_rebind_helper<_Alloc, _Tp>::__value>
67 struct __alloctr_rebind;
69 template<
typename _Alloc,
typename _Tp>
70 struct __alloctr_rebind<_Alloc, _Tp, true>
72 typedef typename _Alloc::template rebind<_Tp>::other __type;
75 template<
template<
typename,
typename...>
class _Alloc,
typename _Tp,
76 typename _Up,
typename... _Args>
77 struct __alloctr_rebind<_Alloc<_Up, _Args...>, _Tp, false>
79 typedef _Alloc<_Tp, _Args...> __type;
86 template<
typename _Alloc>
94 #define _GLIBCXX_ALLOC_TR_NESTED_TYPE(_NTYPE, _ALT) \
96 template<typename _Tp> \
97 static typename _Tp::_NTYPE _S_##_NTYPE##_helper(_Tp*); \
98 static _ALT _S_##_NTYPE##_helper(...); \
99 typedef decltype(_S_##_NTYPE##_helper((_Alloc*)0)) __##_NTYPE; \
120 typedef __const_pointer const_pointer;
131 typedef __void_pointer void_pointer;
142 typedef __const_void_pointer const_void_pointer;
153 typedef __difference_type difference_type;
164 typedef __size_type size_type;
175 typedef __propagate_on_container_copy_assignment
176 propagate_on_container_copy_assignment;
187 typedef __propagate_on_container_move_assignment
188 propagate_on_container_move_assignment;
199 typedef __propagate_on_container_swap propagate_on_container_swap;
201 #undef _GLIBCXX_ALLOC_TR_NESTED_TYPE
203 template<
typename _Tp>
204 using rebind_alloc =
typename __alloctr_rebind<_Alloc, _Tp>::__type;
205 template<
typename _Tp>
209 template<
typename _Alloc2>
210 struct __allocate_helper
212 template<
typename _Alloc3,
213 typename = decltype(std::declval<_Alloc3*>()->
allocate(
214 std::declval<size_type>(),
215 std::declval<const_void_pointer>()))>
221 typedef decltype(__test<_Alloc>(0)) type;
222 static const bool value = type::value;
225 template<
typename _Alloc2>
228 _S_allocate(_Alloc2& __a, size_type __n, const_void_pointer __hint)
229 {
return __a.allocate(__n, __hint); }
231 template<
typename _Alloc2>
233 enable_if<!__allocate_helper<_Alloc2>::value, pointer>::type
234 _S_allocate(_Alloc2& __a, size_type __n, ...)
235 {
return __a.allocate(__n); }
237 template<
typename _Tp,
typename... _Args>
238 struct __construct_helper
240 template<
typename _Alloc2,
241 typename = decltype(std::declval<_Alloc2*>()->
construct(
242 std::declval<_Tp*>(), std::declval<_Args>()...))>
248 typedef decltype(__test<_Alloc>(0)) type;
249 static const
bool value = type::value;
252 template<typename _Tp, typename... _Args>
254 enable_if<__construct_helper<_Tp, _Args...>::value,
void>::type
255 _S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
256 { __a.construct(__p, std::forward<_Args>(__args)...); }
258 template<
typename _Tp,
typename... _Args>
260 enable_if<__and_<__not_<__construct_helper<_Tp, _Args...>>,
261 is_constructible<_Tp, _Args...>>::value,
void>::type
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 typedef decltype(__test<_Alloc>(0)) type;
277 static const
bool value = type::value;
280 template<typename _Tp>
281 static typename enable_if<__destroy_helper<_Tp>::value,
void>::type
282 _S_destroy(_Alloc& __a, _Tp* __p)
283 { __a.destroy(__p); }
285 template<
typename _Tp>
286 static typename enable_if<!__destroy_helper<_Tp>::value,
void>::type
287 _S_destroy(_Alloc&, _Tp* __p)
290 template<
typename _Alloc2>
291 struct __maxsize_helper
293 template<
typename _Alloc3,
294 typename = decltype(std::declval<_Alloc3*>()->
max_size())>
300 typedef decltype(__test<_Alloc2>(0)) type;
301 static const
bool value = type::value;
304 template<typename _Alloc2>
306 enable_if<__maxsize_helper<_Alloc2>::value, size_type>::type
307 _S_max_size(_Alloc2& __a)
308 {
return __a.max_size(); }
310 template<
typename _Alloc2>
312 enable_if<!__maxsize_helper<_Alloc2>::value, size_type>::type
313 _S_max_size(_Alloc2&)
314 {
return __gnu_cxx::__numeric_traits<size_type>::__max; }
316 template<
typename _Alloc2>
317 struct __select_helper
319 template<
typename _Alloc3,
typename
320 = decltype(std::declval<_Alloc3*>()
327 typedef decltype(__test<_Alloc2>(0)) type;
328 static const
bool value = type::value;
330 template<typename _Alloc2>
332 enable_if<__select_helper<_Alloc2>::value, _Alloc2>::type
333 _S_select(_Alloc2& __a)
334 {
return __a.select_on_container_copy_construction(); }
336 template<
typename _Alloc2>
338 enable_if<!__select_helper<_Alloc2>::value, _Alloc2>::type
339 _S_select(_Alloc2& __a)
353 {
return __a.allocate(__n); }
367 allocate(_Alloc& __a, size_type __n, const_void_pointer __hint)
368 {
return _S_allocate(__a, __n, __hint); }
378 static void deallocate(_Alloc& __a, pointer __p, size_type __n)
379 { __a.deallocate(__p, __n); }
392 template<
typename _Tp,
typename... _Args>
393 static auto construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
394 -> decltype(_S_construct(__a, __p, std::forward<_Args>(__args)...))
395 { _S_construct(__a, __p, std::forward<_Args>(__args)...); }
407 { _S_destroy(__a, __p); }
418 {
return _S_max_size(__a); }
430 {
return _S_select(__rhs); }
433 template<
typename _Alloc>
434 template<
typename _Alloc2>
435 const bool allocator_traits<_Alloc>::__allocate_helper<_Alloc2>::value;
437 template<
typename _Alloc>
438 template<
typename _Tp,
typename... _Args>
440 allocator_traits<_Alloc>::__construct_helper<_Tp, _Args...>::value;
442 template<
typename _Alloc>
443 template<
typename _Tp>
444 const bool allocator_traits<_Alloc>::__destroy_helper<_Tp>::value;
446 template<
typename _Alloc>
447 template<
typename _Alloc2>
448 const bool allocator_traits<_Alloc>::__maxsize_helper<_Alloc2>::value;
450 template<
typename _Alloc>
451 template<
typename _Alloc2>
452 const bool allocator_traits<_Alloc>::__select_helper<_Alloc2>::value;
454 template<
typename _Alloc>
456 __do_alloc_on_copy(_Alloc& __one,
const _Alloc& __two,
true_type)
459 template<
typename _Alloc>
461 __do_alloc_on_copy(_Alloc&,
const _Alloc&,
false_type)
464 template<
typename _Alloc>
465 inline void __alloc_on_copy(_Alloc& __one,
const _Alloc& __two)
467 typedef allocator_traits<_Alloc> __traits;
468 typedef typename __traits::propagate_on_container_copy_assignment __pocca;
469 __do_alloc_on_copy(__one, __two, __pocca());
472 template<
typename _Alloc>
473 inline _Alloc __alloc_on_copy(
const _Alloc& __a)
475 typedef allocator_traits<_Alloc> __traits;
476 return __traits::select_on_container_copy_construction(__a);
479 template<
typename _Alloc>
480 inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two,
true_type)
481 { __one = std::move(__two); }
483 template<
typename _Alloc>
484 inline void __do_alloc_on_move(_Alloc&, _Alloc&,
false_type)
487 template<
typename _Alloc>
488 inline void __alloc_on_move(_Alloc& __one, _Alloc& __two)
490 typedef allocator_traits<_Alloc> __traits;
491 typedef typename __traits::propagate_on_container_move_assignment __pocma;
492 __do_alloc_on_move(__one, __two, __pocma());
495 template<
typename _Alloc>
496 inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two,
true_type)
502 template<
typename _Alloc>
503 inline void __do_alloc_on_swap(_Alloc&, _Alloc&,
false_type)
506 template<
typename _Alloc>
507 inline void __alloc_on_swap(_Alloc& __one, _Alloc& __two)
509 typedef allocator_traits<_Alloc> __traits;
510 typedef typename __traits::propagate_on_container_swap __pocs;
511 __do_alloc_on_swap(__one, __two, __pocs());
514 template<
typename _Alloc>
515 class __is_copy_insertable_impl
517 typedef allocator_traits<_Alloc> _Traits;
519 template<
typename _Up,
typename
520 = decltype(_Traits::construct(std::declval<_Alloc&>(),
521 std::declval<_Up*>(),
522 std::declval<const _Up&>()))>
526 template<
typename _Up>
531 typedef decltype(_M_select<typename _Alloc::value_type>(0)) type;
535 template<typename _Alloc>
536 struct __is_copy_insertable
537 : __is_copy_insertable_impl<_Alloc>::type
541 template<
typename _Tp>
542 struct __is_copy_insertable<allocator<_Tp>>
543 : is_copy_constructible<_Tp>
547 template<
bool>
struct __allow_copy_cons { };
551 struct __allow_copy_cons<false>
553 __allow_copy_cons() =
default;
554 __allow_copy_cons(
const __allow_copy_cons&) =
delete;
555 __allow_copy_cons(__allow_copy_cons&&) =
default;
556 __allow_copy_cons& operator=(
const __allow_copy_cons&) =
default;
557 __allow_copy_cons& operator=(__allow_copy_cons&&) =
default;
560 template<
typename _Alloc>
561 using __check_copy_constructible
562 = __allow_copy_cons<__is_copy_insertable<_Alloc>::value>;
564 _GLIBCXX_END_NAMESPACE_VERSION
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
The standard allocator, as per [20.4].
__size_type size_type
The allocator's size type.
static pointer allocate(_Alloc &__a, size_type __n, const_void_pointer __hint)
Allocate memory.
Uniform interface to all pointer-like types.
__void_pointer void_pointer
The allocator's void pointer type.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
static pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
Define a member typedef type only if a boolean constant is true.
__propagate_on_container_copy_assignment propagate_on_container_copy_assignment
How the allocator is propagated on copy assignment.
__difference_type difference_type
The allocator's difference type.
_Alloc allocator_type
The allocator type.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
static size_type max_size(const _Alloc &__a)
The maximum supported allocation size.
static auto construct(_Alloc &__a, _Tp *__p, _Args &&...__args) -> decltype(_S_construct(__a, __p, std::forward< _Args >(__args)...))
Construct an object of type _Tp.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
__const_pointer const_pointer
The allocator's const pointer type.
__propagate_on_container_swap propagate_on_container_swap
How the allocator is propagated on swap.
Uniform interface to all allocator types.
static _Alloc select_on_container_copy_construction(const _Alloc &__rhs)
Obtain an allocator to use when copying a container.
__pointer pointer
The allocator's pointer type.
__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.
static void destroy(_Alloc &__a, _Tp *__p)
Destroy an object of type _Tp.
_Alloc::value_type value_type
The allocated type.