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 
tbb::internal::allocator_traits::deallocate
static void deallocate(Alloc &a, pointer p, size_type n)
Definition: _allocator_traits.h:106
tbb::internal::allocator_traits::const_pointer
allocator_type::const_pointer const_pointer
Definition: _allocator_traits.h:94
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::internal::allocator_traits::construct
static void construct(Alloc &, PT *p, __TBB_FORWARDING_REF(T1) t1, __TBB_FORWARDING_REF(T2) t2)
Definition: _allocator_traits.h:121
tbb::internal::allocator_traits::rebind_alloc
Definition: _allocator_traits.h:98
tbb::internal::allocator_copy_assignment
void allocator_copy_assignment(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
Definition: _allocator_traits.h:49
__TBB_FORWARDING_REF
#define __TBB_FORWARDING_REF(A)
Definition: tbb_stddef.h:517
tbb::internal::allocator_traits::construct
static void construct(Alloc &, PT *p)
Definition: _allocator_traits.h:111
tbb::internal::allocator_move_assignment
void allocator_move_assignment(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
Definition: _allocator_traits.h:59
tbb::internal::allocator_traits::destroy
static void destroy(Alloc &, T *p)
Definition: _allocator_traits.h:133
tbb::internal::allocator_traits::pointer
allocator_type::pointer pointer
Definition: _allocator_traits.h:93
tbb::internal::allocator_traits::value_type
allocator_type::value_type value_type
Definition: _allocator_traits.h:91
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::internal::traits_true_type
tbb::internal::true_type traits_true_type
Definition: _allocator_traits.h:42
tbb::internal::allocator_swap
void allocator_swap(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
Definition: _allocator_traits.h:69
tbb::internal::swap
void swap(atomic< T > &lhs, atomic< T > &rhs)
Definition: atomic.h:564
tbb::internal::traits_false_type
tbb::internal::false_type traits_false_type
Definition: _allocator_traits.h:43
tbb::internal::allocator_traits::select_on_container_copy_construction
static Alloc select_on_container_copy_construction(const Alloc &a)
Definition: _allocator_traits.h:138
tbb::internal::allocator_traits::allocator_type
Alloc allocator_type
Definition: _allocator_traits.h:90
tbb::internal::allocator_traits::allocate
static pointer allocate(Alloc &a, size_type n)
Definition: _allocator_traits.h:102
tbb::internal::allocator_traits::propagate_on_container_copy_assignment
tbb::internal::false_type propagate_on_container_copy_assignment
Definition: _allocator_traits.h:87
tbb::internal::allocator_traits::difference_type
allocator_type::difference_type difference_type
Definition: _allocator_traits.h:95
tbb::internal::allocator_type::value_type
T value_type
Definition: tbb_stddef.h:472
tbb::internal::allocator_traits::size_type
allocator_type::size_type size_type
Definition: _allocator_traits.h:96
tbb::move
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319
tbb::internal::allocator_traits::rebind_alloc::other
Alloc::template rebind< U >::other other
Definition: _allocator_traits.h:99
tbb::internal::bool_constant
Definition: tbb_stddef.h:486
tbb::internal::true_type
bool_constant< true > true_type
Definition: tbb_stddef.h:489
tbb::internal::allocator_traits
Definition: _allocator_traits.h:82
tbb::internal::allocator_traits::propagate_on_container_move_assignment
tbb::internal::false_type propagate_on_container_move_assignment
Definition: _allocator_traits.h:86
tbb::internal::suppress_unused_warning
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398
tbb::internal::allocator_traits::construct
static void construct(Alloc &, PT *p, __TBB_FORWARDING_REF(T1) t1)
Definition: _allocator_traits.h:116
tbb::internal::allocator_traits::propagate_on_container_swap
tbb::internal::false_type propagate_on_container_swap
Definition: _allocator_traits.h:88
tbb::internal::false_type
bool_constant< false > false_type
Definition: tbb_stddef.h:490
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
tbb::internal::allocator_traits::construct
static void construct(Alloc &, PT *p, __TBB_FORWARDING_REF(T1) t1, __TBB_FORWARDING_REF(T2) t2, __TBB_FORWARDING_REF(T3) t3)
Definition: _allocator_traits.h:126
tbb::internal::allocator_rebind::type
allocator_traits< Alloc >::template rebind_alloc< T >::other type
Definition: _allocator_traits.h:149
tbb::internal::allocator_rebind
Definition: _allocator_traits.h:145

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.