File indexing completed on 2025-01-18 10:12:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef __TBB_allocator_traits_H
0018 #define __TBB_allocator_traits_H
0019
0020 #include "../tbb_stddef.h" // true/false_type
0021
0022 #if __TBB_ALLOCATOR_TRAITS_PRESENT
0023 #include <memory> // for allocator_traits
0024 #endif
0025
0026 #if __TBB_CPP11_RVALUE_REF_PRESENT
0027 #include <utility> // for std::move
0028 #endif
0029
0030
0031 #include __TBB_STD_SWAP_HEADER
0032
0033 namespace tbb {
0034 namespace internal {
0035
0036
0037
0038 #if __TBB_ALLOCATOR_TRAITS_PRESENT
0039 typedef std::true_type traits_true_type;
0040 typedef std::false_type traits_false_type;
0041 #else
0042 typedef tbb::internal::true_type traits_true_type;
0043 typedef tbb::internal::false_type traits_false_type;
0044 #endif
0045
0046
0047
0048 template <typename MyAlloc, typename OtherAlloc>
0049 inline void allocator_copy_assignment(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
0050 my_allocator = other_allocator;
0051 }
0052 template <typename MyAlloc, typename OtherAlloc>
0053 inline void allocator_copy_assignment(MyAlloc&, OtherAlloc&, traits_false_type) { }
0054
0055 #if __TBB_CPP11_RVALUE_REF_PRESENT
0056
0057
0058 template <typename MyAlloc, typename OtherAlloc>
0059 inline void allocator_move_assignment(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
0060 my_allocator = std::move(other_allocator);
0061 }
0062 template <typename MyAlloc, typename OtherAlloc>
0063 inline void allocator_move_assignment(MyAlloc&, OtherAlloc&, traits_false_type) { }
0064 #endif
0065
0066
0067
0068 template <typename MyAlloc, typename OtherAlloc>
0069 inline void allocator_swap(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
0070 using std::swap;
0071 swap(my_allocator, other_allocator);
0072 }
0073 template <typename MyAlloc, typename OtherAlloc>
0074 inline void allocator_swap(MyAlloc&, OtherAlloc&, traits_false_type) { }
0075
0076 #if __TBB_ALLOCATOR_TRAITS_PRESENT
0077 using std::allocator_traits;
0078 #else
0079
0080
0081 template<typename Alloc>
0082 struct allocator_traits {
0083
0084
0085
0086 typedef tbb::internal::false_type propagate_on_container_move_assignment;
0087 typedef tbb::internal::false_type propagate_on_container_copy_assignment;
0088 typedef tbb::internal::false_type propagate_on_container_swap;
0089
0090 typedef Alloc allocator_type;
0091 typedef typename allocator_type::value_type value_type;
0092
0093 typedef typename allocator_type::pointer pointer;
0094 typedef typename allocator_type::const_pointer const_pointer;
0095 typedef typename allocator_type::difference_type difference_type;
0096 typedef typename allocator_type::size_type size_type;
0097
0098 template <typename U> struct rebind_alloc {
0099 typedef typename Alloc::template rebind<U>::other other;
0100 };
0101
0102 static pointer allocate(Alloc& a, size_type n) {
0103 return a.allocate(n);
0104 }
0105
0106 static void deallocate(Alloc& a, pointer p, size_type n) {
0107 a.deallocate(p, n);
0108 }
0109
0110 template<typename PT>
0111 static void construct(Alloc&, PT* p) {
0112 ::new (static_cast<void*>(p)) PT();
0113 }
0114
0115 template<typename PT, typename T1>
0116 static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1) {
0117 ::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1));
0118 }
0119
0120 template<typename PT, typename T1, typename T2>
0121 static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1, __TBB_FORWARDING_REF(T2) t2) {
0122 ::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1), tbb::internal::forward<T2>(t2));
0123 }
0124
0125 template<typename PT, typename T1, typename T2, typename T3>
0126 static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1,
0127 __TBB_FORWARDING_REF(T2) t2, __TBB_FORWARDING_REF(T3) t3) {
0128 ::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1), tbb::internal::forward<T2>(t2),
0129 tbb::internal::forward<T3>(t3));
0130 }
0131
0132 template<typename T>
0133 static void destroy(Alloc&, T* p) {
0134 p->~T();
0135 tbb::internal::suppress_unused_warning(p);
0136 }
0137
0138 static Alloc select_on_container_copy_construction(const Alloc& a) { return a; }
0139 };
0140 #endif
0141
0142
0143
0144 template<typename Alloc, typename T>
0145 struct allocator_rebind {
0146 #if __TBB_ALLOCATOR_TRAITS_PRESENT
0147 typedef typename allocator_traits<Alloc>::template rebind_alloc<T> type;
0148 #else
0149 typedef typename allocator_traits<Alloc>::template rebind_alloc<T>::other type;
0150 #endif
0151 };
0152
0153 }}
0154
0155 #endif
0156