_allocator_traits.h
Go to the documentation of this file.
/*
Copyright (c) 2019-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __TBB_allocator_traits_H
#define __TBB_allocator_traits_H
#include "../tbb_stddef.h" // true/false_type
#if __TBB_ALLOCATOR_TRAITS_PRESENT
#include <memory> // for allocator_traits
#endif
#if __TBB_CPP11_RVALUE_REF_PRESENT
#include <utility> // for std::move
#endif
// For allocator_swap helper
#include __TBB_STD_SWAP_HEADER
namespace tbb {
namespace internal {
#if __TBB_ALLOCATOR_TRAITS_PRESENT
typedef std::true_type traits_true_type;
typedef std::false_type traits_false_type;
#else
typedef tbb::internal::true_type traits_true_type;
typedef tbb::internal::false_type traits_false_type;
#endif
template <typename MyAlloc, typename OtherAlloc>
inline void allocator_copy_assignment(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
my_allocator = other_allocator;
}
template <typename MyAlloc, typename OtherAlloc>
inline void allocator_copy_assignment(MyAlloc&, OtherAlloc&, traits_false_type) { /* NO COPY */}
#if __TBB_CPP11_RVALUE_REF_PRESENT
template <typename MyAlloc, typename OtherAlloc>
inline void allocator_move_assignment(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
my_allocator = std::move(other_allocator);
}
template <typename MyAlloc, typename OtherAlloc>
inline void allocator_move_assignment(MyAlloc&, OtherAlloc&, traits_false_type) { /* NO MOVE */ }
#endif
template <typename MyAlloc, typename OtherAlloc>
inline void allocator_swap(MyAlloc& my_allocator, OtherAlloc& other_allocator, traits_true_type) {
using std::swap;
swap(my_allocator, other_allocator);
}
template <typename MyAlloc, typename OtherAlloc>
inline void allocator_swap(MyAlloc&, OtherAlloc&, traits_false_type) { /* NO SWAP */ }
#if __TBB_ALLOCATOR_TRAITS_PRESENT
using std::allocator_traits;
#else
template<typename Alloc>
struct allocator_traits {
// C++03 allocator doesn't have to be assignable or swappable, therefore
// define these traits as false_type to do not require additional operations
// that are not supposed to be in.
typedef tbb::internal::false_type propagate_on_container_move_assignment;
typedef tbb::internal::false_type propagate_on_container_copy_assignment;
typedef tbb::internal::false_type propagate_on_container_swap;
typedef Alloc allocator_type;
typedef typename allocator_type::value_type value_type;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
typedef typename allocator_type::difference_type difference_type;
typedef typename allocator_type::size_type size_type;
template <typename U> struct rebind_alloc {
typedef typename Alloc::template rebind<U>::other other;
};
static pointer allocate(Alloc& a, size_type n) {
return a.allocate(n);
}
static void deallocate(Alloc& a, pointer p, size_type n) {
a.deallocate(p, n);
}
template<typename PT>
static void construct(Alloc&, PT* p) {
::new (static_cast<void*>(p)) PT();
}
template<typename PT, typename T1>
static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1) {
::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1));
}
template<typename PT, typename T1, typename T2>
static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1, __TBB_FORWARDING_REF(T2) t2) {
::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1), tbb::internal::forward<T2>(t2));
}
template<typename PT, typename T1, typename T2, typename T3>
static void construct(Alloc&, PT* p, __TBB_FORWARDING_REF(T1) t1,
__TBB_FORWARDING_REF(T2) t2, __TBB_FORWARDING_REF(T3) t3) {
::new (static_cast<void*>(p)) PT(tbb::internal::forward<T1>(t1), tbb::internal::forward<T2>(t2),
tbb::internal::forward<T3>(t3));
}
template<typename T>
static void destroy(Alloc&, T* p) {
p->~T();
tbb::internal::suppress_unused_warning(p);
}
static Alloc select_on_container_copy_construction(const Alloc& a) { return a; }
};
#endif // __TBB_ALLOCATOR_TRAITS_PRESENT
template<typename Alloc, typename T>
struct allocator_rebind {
#if __TBB_ALLOCATOR_TRAITS_PRESENT
typedef typename allocator_traits<Alloc>::template rebind_alloc<T> type;
#else
typedef typename allocator_traits<Alloc>::template rebind_alloc<T>::other type;
#endif
};
}} // namespace tbb::internal
#endif // __TBB_allocator_traits_H
__TBB_FORWARDING_REF
#define __TBB_FORWARDING_REF(A)
Definition: tbb_stddef.h:517
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::move
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319
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::allocator_move_assignment
void allocator_move_assignment(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
Definition: _allocator_traits.h:59
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_copy_assignment
void allocator_copy_assignment(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
Definition: _allocator_traits.h:49
tbb::internal::false_type
bool_constant< false > false_type
Definition: tbb_stddef.h:490
tbb::internal::traits_false_type
tbb::internal::false_type traits_false_type
Definition: _allocator_traits.h:43
tbb::internal::true_type
bool_constant< true > true_type
Definition: tbb_stddef.h:489
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::internal::allocator_traits
Definition: _allocator_traits.h:82
tbb::internal::allocator_traits::deallocate
static void deallocate(Alloc &a, pointer p, size_type n)
Definition: _allocator_traits.h:106
tbb::internal::allocator_traits::construct
static void construct(Alloc &, PT *p)
Definition: _allocator_traits.h:111
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::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::size_type
allocator_type::size_type size_type
Definition: _allocator_traits.h:96
tbb::internal::allocator_traits::value_type
allocator_type::value_type value_type
Definition: _allocator_traits.h:91
tbb::internal::allocator_traits::allocator_type
Alloc allocator_type
Definition: _allocator_traits.h:90
tbb::internal::allocator_traits::difference_type
allocator_type::difference_type difference_type
Definition: _allocator_traits.h:95
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_move_assignment
tbb::internal::false_type propagate_on_container_move_assignment
Definition: _allocator_traits.h:86
tbb::internal::allocator_traits::propagate_on_container_swap
tbb::internal::false_type propagate_on_container_swap
Definition: _allocator_traits.h:88
tbb::internal::allocator_traits::const_pointer
allocator_type::const_pointer const_pointer
Definition: _allocator_traits.h:94
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::pointer
allocator_type::pointer pointer
Definition: _allocator_traits.h:93
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_traits::destroy
static void destroy(Alloc &, T *p)
Definition: _allocator_traits.h:133
tbb::internal::allocator_traits::rebind_alloc
Definition: _allocator_traits.h:98
tbb::internal::allocator_traits::rebind_alloc::other
Alloc::template rebind< U >::other other
Definition: _allocator_traits.h:99
tbb::internal::allocator_rebind
Definition: _allocator_traits.h:145
tbb::internal::allocator_rebind::type
allocator_traits< Alloc >::template rebind_alloc< T >::other type
Definition: _allocator_traits.h:149
tbb::internal::allocator_type::value_type
T value_type
Definition: tbb_stddef.h:472
tbb::internal::bool_constant
Definition: tbb_stddef.h:486

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.