Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:44

0001 /*
0002     Copyright (c) 2019-2020 Intel Corporation
0003 
0004     Licensed under the Apache License, Version 2.0 (the "License");
0005     you may not use this file except in compliance with the License.
0006     You may obtain a copy of the License at
0007 
0008         http://www.apache.org/licenses/LICENSE-2.0
0009 
0010     Unless required by applicable law or agreed to in writing, software
0011     distributed under the License is distributed on an "AS IS" BASIS,
0012     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     See the License for the specific language governing permissions and
0014     limitations under the License.
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 // For allocator_swap helper
0031 #include __TBB_STD_SWAP_HEADER
0032 
0033 namespace tbb {
0034 namespace internal {
0035 
0036 //! Internal implementation of allocator traits, propagate_on_* use internal boolean_constant.
0037 //! In order to avoid code duplication, check what implementation of boolean constant will likely be passed.
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 //! Copy assignment implementation for allocator if propagate_on_container_copy_assignment == true_type
0047 //! Noop if pocca == false_type
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) { /* NO COPY */}
0054 
0055 #if __TBB_CPP11_RVALUE_REF_PRESENT
0056 //! Move assignment implementation for allocator if propagate_on_container_move_assignment == true_type.
0057 //! Noop if pocma == false_type.
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) { /* NO MOVE */ }
0064 #endif
0065 
0066 //! Swap implementation for allocators if propagate_on_container_swap == true_type.
0067 //! Noop if pocs == false_type.
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) { /* NO SWAP */ }
0075 
0076 #if __TBB_ALLOCATOR_TRAITS_PRESENT
0077 using std::allocator_traits;
0078 #else
0079 //! Internal allocator_traits implementation, which relies on C++03 standard
0080 //! [20.1.5] allocator requirements
0081 template<typename Alloc>
0082 struct allocator_traits {
0083     // C++03 allocator doesn't have to be assignable or swappable, therefore
0084     // define these traits as false_type to do not require additional operations
0085     // that are not supposed to be in.
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 // __TBB_ALLOCATOR_TRAITS_PRESENT
0141 
0142 //! C++03/C++11 compliant rebind helper, even if no std::allocator_traits available
0143 //! or rebind is not defined for allocator type
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 }} // namespace tbb::internal
0154 
0155 #endif // __TBB_allocator_traits_H
0156