Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
_allocator_traits.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2019-2020 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #ifndef __TBB_allocator_traits_H
18 #define __TBB_allocator_traits_H
19 
20 #include "../tbb_stddef.h" // true/false_type
21 
22 #if __TBB_ALLOCATOR_TRAITS_PRESENT
23 #include <memory> // for allocator_traits
24 #endif
25 
26 #if __TBB_CPP11_RVALUE_REF_PRESENT
27 #include <utility> // for std::move
28 #endif
29 
30 // For allocator_swap helper
31 #include __TBB_STD_SWAP_HEADER
32 
33 namespace tbb {
34 namespace internal {
35 
38 #if __TBB_ALLOCATOR_TRAITS_PRESENT
41 #else
44 #endif
45 
48 template <typename MyAlloc, typename OtherAlloc>
49 inline void allocator_copy_assignment(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
50  my_allocator = other_allocator;
51 }
52 template <typename MyAlloc, typename OtherAlloc>
53 inline void allocator_copy_assignment(MyAlloc&, OtherAlloc&, traits_false_type) { /* NO COPY */}
54 
55 #if __TBB_CPP11_RVALUE_REF_PRESENT
56 template <typename MyAlloc, typename OtherAlloc>
59 inline void allocator_move_assignment(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
60  my_allocator = std::move(other_allocator);
61 }
62 template <typename MyAlloc, typename OtherAlloc>
63 inline void allocator_move_assignment(MyAlloc&, OtherAlloc&, traits_false_type) { /* NO MOVE */ }
64 #endif
65 
68 template <typename MyAlloc, typename OtherAlloc>
69 inline void allocator_swap(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
70  using std::swap;
71  swap(my_allocator, other_allocator);
72 }
73 template <typename MyAlloc, typename OtherAlloc>
74 inline void allocator_swap(MyAlloc&, OtherAlloc&, traits_false_type) { /* NO SWAP */ }
75 
76 #if __TBB_ALLOCATOR_TRAITS_PRESENT
77 using std::allocator_traits;
78 #else
79 template<typename Alloc>
83  // C++03 allocator doesn't have to be assignable or swappable, therefore
84  // define these traits as false_type to do not require additional operations
85  // that are not supposed to be in.
89 
90  typedef Alloc allocator_type;
92 
93  typedef typename allocator_type::pointer pointer;
94  typedef typename allocator_type::const_pointer const_pointer;
95  typedef typename allocator_type::difference_type difference_type;
96  typedef typename allocator_type::size_type size_type;
97 
98  template <typename U> struct rebind_alloc {
99  typedef typename Alloc::template rebind<U>::other other;
100  };
101 
102  static pointer allocate(Alloc& a, size_type n) {
103  return a.allocate(n);
104  }
105 
106  static void deallocate(Alloc& a, pointer p, size_type n) {
107  a.deallocate(p, n);
108  }
109 
110  template<typename PT>
111  static void construct(Alloc&, PT* p) {
112  ::new (static_cast<void*>(p)) PT();
113  }
114 
115  template<typename PT, typename T1>
116  static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1) {
117  ::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1));
118  }
119 
120  template<typename PT, typename T1, typename T2>
121  static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1, __TBB_FORWARDING_REF(T2) t2) {
122  ::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1), tbb::internal::forward<T2>(t2));
123  }
124 
125  template<typename PT, typename T1, typename T2, typename T3>
126  static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1,
128  ::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1), tbb::internal::forward<T2>(t2),
129  tbb::internal::forward<T3>(t3));
130  }
131 
132  template<typename T>
133  static void destroy(Alloc&, T* p) {
134  p->~T();
136  }
137 
138  static Alloc select_on_container_copy_construction(const Alloc& a) { return a; }
139 };
140 #endif // __TBB_ALLOCATOR_TRAITS_PRESENT
141 
144 template<typename Alloc, typename T>
146 #if __TBB_ALLOCATOR_TRAITS_PRESENT
147  typedef typename allocator_traits<Alloc>::template rebind_alloc<T> type;
148 #else
149  typedef typename allocator_traits<Alloc>::template rebind_alloc<T>::other type;
150 #endif
151 };
152 
153 }} // namespace tbb::internal
154 
155 #endif // __TBB_allocator_traits_H
156 
bool_constant< true > true_type
Definition: tbb_stddef.h:489
void allocator_swap(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
tbb::internal::true_type traits_true_type
allocator_type::value_type value_type
static void construct(Alloc &, PT *p, __TBB_FORWARDING_REF(T1) t1)
tbb::internal::false_type propagate_on_container_swap
void allocator_move_assignment(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
static void construct(Alloc &, PT *p, __TBB_FORWARDING_REF(T1) t1, __TBB_FORWARDING_REF(T2) t2, __TBB_FORWARDING_REF(T3) t3)
bool_constant< false > false_type
Definition: tbb_stddef.h:490
allocator_traits< Alloc >::template rebind_alloc< T >::other type
static void construct(Alloc &, PT *p)
static pointer allocate(Alloc &a, size_type n)
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398
allocator_type::size_type size_type
void allocator_copy_assignment(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
tbb::internal::false_type propagate_on_container_copy_assignment
static Alloc select_on_container_copy_construction(const Alloc &a)
void const char const char int ITT_FORMAT __itt_group_sync p
Alloc::template rebind< U >::other other
allocator_type::const_pointer const_pointer
tbb::internal::false_type propagate_on_container_move_assignment
static void deallocate(Alloc &a, pointer p, size_type n)
allocator_type::pointer pointer
void swap(atomic< T > &lhs, atomic< T > &rhs)
Definition: atomic.h:564
static void destroy(Alloc &, T *p)
#define __TBB_FORWARDING_REF(A)
Definition: tbb_stddef.h:517
static void construct(Alloc &, PT *p, __TBB_FORWARDING_REF(T1) t1, __TBB_FORWARDING_REF(T2) t2)
The graph class.
allocator_type::difference_type difference_type
tbb::internal::false_type traits_false_type
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.