Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-30 08:46:14

0001 /*
0002     Copyright (c) 2005-2021 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_detail__allocator_traits_H
0018 #define __TBB_detail__allocator_traits_H
0019 
0020 #include "_config.h"
0021 #include "_template_helpers.h"
0022 #include <memory>
0023 #include <type_traits>
0024 
0025 namespace tbb {
0026 namespace detail {
0027 inline namespace d0 {
0028 
0029 #if !__TBB_CPP17_ALLOCATOR_IS_ALWAYS_EQUAL_PRESENT
0030 // Struct is_always_equal_detector provides the member type "type" which is
0031 // Allocator::is_always_equal if it is present, std::false_type otherwise
0032 template <typename Allocator, typename = void>
0033 struct is_always_equal_detector {
0034     using type = std::false_type;
0035 };
0036 
0037 template <typename Allocator>
0038 struct is_always_equal_detector<Allocator, tbb::detail::void_t<typename Allocator::is_always_equal>>
0039 {
0040     using type = typename Allocator::is_always_equal;
0041 };
0042 #endif // !__TBB_CPP17_ALLOCATOR_IS_ALWAYS_EQUAL_PRESENT
0043 
0044 template <typename Allocator>
0045 class allocator_traits : public std::allocator_traits<Allocator>
0046 {
0047     using base_type = std::allocator_traits<Allocator>;
0048 public:
0049 #if !__TBB_CPP17_ALLOCATOR_IS_ALWAYS_EQUAL_PRESENT
0050     using is_always_equal = typename is_always_equal_detector<Allocator>::type;
0051 #endif
0052 
0053     template <typename T>
0054     using rebind_traits = typename tbb::detail::allocator_traits<typename base_type::template rebind_alloc<T>>;
0055 }; // struct allocator_traits
0056 
0057 template <typename Allocator>
0058 void copy_assign_allocators_impl( Allocator& lhs, const Allocator& rhs, /*pocca = */std::true_type ) {
0059     lhs = rhs;
0060 }
0061 
0062 template <typename Allocator>
0063 void copy_assign_allocators_impl( Allocator&, const Allocator&, /*pocca = */ std::false_type ) {}
0064 
0065 // Copy assigns allocators only if propagate_on_container_copy_assignment is true
0066 template <typename Allocator>
0067 void copy_assign_allocators( Allocator& lhs, const Allocator& rhs ) {
0068     using pocca_type = typename allocator_traits<Allocator>::propagate_on_container_copy_assignment;
0069     copy_assign_allocators_impl(lhs, rhs, pocca_type());
0070 }
0071 
0072 template <typename Allocator>
0073 void move_assign_allocators_impl( Allocator& lhs, Allocator& rhs, /*pocma = */ std::true_type ) {
0074     lhs = std::move(rhs);
0075 }
0076 
0077 template <typename Allocator>
0078 void move_assign_allocators_impl( Allocator&, Allocator&, /*pocma = */ std::false_type ) {}
0079 
0080 // Move assigns allocators only if propagate_on_container_move_assignment is true
0081 template <typename Allocator>
0082 void move_assign_allocators( Allocator& lhs, Allocator& rhs ) {
0083     using pocma_type = typename allocator_traits<Allocator>::propagate_on_container_move_assignment;
0084     move_assign_allocators_impl(lhs, rhs, pocma_type());
0085 }
0086 
0087 template <typename Allocator>
0088 void swap_allocators_impl( Allocator& lhs, Allocator& rhs, /*pocs = */ std::true_type ) {
0089     using std::swap;
0090     swap(lhs, rhs);
0091 }
0092 
0093 template <typename Allocator>
0094 void swap_allocators_impl( Allocator&, Allocator&, /*pocs = */ std::false_type ) {}
0095 
0096 // Swaps allocators only if propagate_on_container_swap is true
0097 template <typename Allocator>
0098 void swap_allocators( Allocator& lhs, Allocator& rhs ) {
0099     using pocs_type = typename allocator_traits<Allocator>::propagate_on_container_swap;
0100     swap_allocators_impl(lhs, rhs, pocs_type());
0101 }
0102 
0103 } // inline namespace d0
0104 } // namespace detail
0105 } // namespace tbb
0106 
0107 #endif // __TBB_detail__allocator_traits_H