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 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 
18 
19 */
20 
21 #ifndef __TBB_allocator_traits_H
22 #define __TBB_allocator_traits_H
23 
24 #include "../tbb_stddef.h" // true/false_type
25 
26 #if __TBB_ALLOCATOR_TRAITS_PRESENT
27 #include <memory> // for allocator_traits
28 #endif
29 
30 #if __TBB_CPP11_RVALUE_REF_PRESENT
31 #include <utility> // for std::move
32 #endif
33 
34 // For allocator_swap helper
35 #include __TBB_STD_SWAP_HEADER
36 
37 namespace tbb {
38 namespace internal {
39 
42 #if __TBB_ALLOCATOR_TRAITS_PRESENT
45 #else
48 #endif
49 
50 #if __TBB_CPP11_RVALUE_REF_PRESENT
51 template <typename MyAlloc, typename OtherAlloc>
54 inline void allocator_move_assignment(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
55  my_allocator = std::move(other_allocator);
56 }
57 template <typename MyAlloc, typename OtherAlloc>
58 inline void allocator_move_assignment(MyAlloc&, OtherAlloc&, traits_false_type) { /* NO MOVE */ }
59 #endif
60 
63 template <typename MyAlloc, typename OtherAlloc>
64 inline void allocator_swap(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
65  using std::swap;
66  swap(my_allocator, other_allocator);
67 }
68 template <typename MyAlloc, typename OtherAlloc>
69 inline void allocator_swap(MyAlloc&, OtherAlloc&, traits_false_type) { /* NO SWAP */ }
70 
71 #if __TBB_ALLOCATOR_TRAITS_PRESENT
72 using std::allocator_traits;
73 #else
74 template<typename Alloc>
78  // C++03 allocator doesn't have to be assignable or swappable, therefore
79  // define these traits as false_type to do not require additional operations
80  // that are not supposed to be in.
84 
85  typedef Alloc allocator_type;
87 
88  typedef typename allocator_type::pointer pointer;
89  typedef typename allocator_type::const_pointer const_pointer;
90  typedef typename allocator_type::difference_type difference_type;
91  typedef typename allocator_type::size_type size_type;
92 
93  template <typename U> struct rebind_alloc {
94  typedef typename Alloc::template rebind<U>::other other;
95  };
96 
97  static pointer allocate(Alloc& a, size_type n) {
98  return a.allocate(n);
99  }
100 
101  static void deallocate(Alloc& a, pointer p, size_type n) {
102  a.deallocate(p, n);
103  }
104 
105  template<typename PT>
106  static void construct(Alloc&, PT* p) {
107  ::new (static_cast<void*>(p)) PT();
108  }
109 
110  template<typename PT, typename T1>
111  static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1) {
112  ::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1));
113  }
114 
115  template<typename PT, typename T1, typename T2>
116  static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1, __TBB_FORWARDING_REF(T2) t2) {
117  ::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1), tbb::internal::forward<T2>(t2));
118  }
119 
120  template<typename PT, typename T1, typename T2, typename T3>
121  static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1,
123  ::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1), tbb::internal::forward<T2>(t2),
124  tbb::internal::forward<T3>(t3));
125  }
126 
127  template<typename T>
128  static void destroy(Alloc&, T* p) {
129  p->~T();
131  }
132 };
133 #endif // __TBB_ALLOCATOR_TRAITS_PRESENT
134 
137 template<typename Alloc, typename T>
139 #if __TBB_ALLOCATOR_TRAITS_PRESENT
140  typedef typename allocator_traits<Alloc>::template rebind_alloc<T> type;
141 #else
142  typedef typename allocator_traits<Alloc>::template rebind_alloc<T>::other type;
143 #endif
144 };
145 
146 }} // namespace tbb::internal
147 
148 #endif // __TBB_allocator_traits_H
149 
Alloc::template rebind< U >::other other
allocator_type::value_type value_type
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:381
bool_constant< true > true_type
Definition: tbb_stddef.h:472
allocator_traits< Alloc >::template rebind_alloc< T >::other type
tbb::internal::false_type propagate_on_container_swap
void swap(atomic< T > &lhs, atomic< T > &rhs)
Definition: atomic.h:539
static pointer allocate(Alloc &a, size_type n)
static void construct(Alloc &, PT *p, __TBB_FORWARDING_REF(T1) t1, __TBB_FORWARDING_REF(T2) t2, __TBB_FORWARDING_REF(T3) t3)
void const char const char int ITT_FORMAT __itt_group_sync p
static void deallocate(Alloc &a, pointer p, size_type n)
allocator_type::size_type size_type
static void construct(Alloc &, PT *p)
tbb::internal::false_type propagate_on_container_move_assignment
static void construct(Alloc &, PT *p, __TBB_FORWARDING_REF(T1) t1, __TBB_FORWARDING_REF(T2) t2)
#define __TBB_FORWARDING_REF(A)
Definition: tbb_stddef.h:500
tbb::internal::false_type propagate_on_container_copy_assignment
The graph class.
tbb::internal::true_type traits_true_type
allocator_type::const_pointer const_pointer
void allocator_move_assignment(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:309
void allocator_swap(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
tbb::internal::false_type traits_false_type
bool_constant< false > false_type
Definition: tbb_stddef.h:473
static void destroy(Alloc &, T *p)
allocator_type::pointer pointer
static void construct(Alloc &, PT *p, __TBB_FORWARDING_REF(T1) t1)
allocator_type::difference_type difference_type

Copyright © 2005-2019 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.