File indexing completed on 2025-07-30 08:46:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
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
0031
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
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 };
0056
0057 template <typename Allocator>
0058 void copy_assign_allocators_impl( Allocator& lhs, const Allocator& rhs, std::true_type ) {
0059 lhs = rhs;
0060 }
0061
0062 template <typename Allocator>
0063 void copy_assign_allocators_impl( Allocator&, const Allocator&, std::false_type ) {}
0064
0065
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, std::true_type ) {
0074 lhs = std::move(rhs);
0075 }
0076
0077 template <typename Allocator>
0078 void move_assign_allocators_impl( Allocator&, Allocator&, std::false_type ) {}
0079
0080
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, std::true_type ) {
0089 using std::swap;
0090 swap(lhs, rhs);
0091 }
0092
0093 template <typename Allocator>
0094 void swap_allocators_impl( Allocator&, Allocator&, std::false_type ) {}
0095
0096
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 }
0104 }
0105 }
0106
0107 #endif