diff --git a/include/oneapi/tbb/concurrent_queue.h b/include/oneapi/tbb/concurrent_queue.h index cab15e76c9..4749bd9ac9 100644 --- a/include/oneapi/tbb/concurrent_queue.h +++ b/include/oneapi/tbb/concurrent_queue.h @@ -140,9 +140,7 @@ class concurrent_queue { if (my_queue_representation == other.my_queue_representation) return *this; clear(); - if (queue_allocator_traits::propagate_on_container_move_assignment::value) { - my_allocator = other.my_allocator; - } + tbb::detail::copy_assign_allocators(my_allocator, other.my_allocator); my_queue_representation->assign(*other.my_queue_representation, my_allocator, copy_construct_item); return *this; } @@ -152,7 +150,7 @@ class concurrent_queue { return *this; clear(); if (queue_allocator_traits::propagate_on_container_move_assignment::value) { - my_allocator = std::move(other.my_allocator); + tbb::detail::move_assign_allocators(my_allocator, other.my_allocator); internal_swap(other); } else { if (my_allocator == other.my_allocator) { @@ -182,12 +180,7 @@ class concurrent_queue { } void swap ( concurrent_queue& other ) { - if (queue_allocator_traits::propagate_on_container_swap::value) { - using std::swap; - swap(my_allocator, other.my_allocator); - } else { - __TBB_ASSERT(my_allocator == other.my_allocator, "unequal allocators"); - } + tbb::detail::swap_allocators(my_allocator, other.my_allocator); internal_swap(other); } @@ -425,9 +418,7 @@ class concurrent_bounded_queue { if (my_queue_representation == other.my_queue_representation) return *this; clear(); - if (queue_allocator_traits::propagate_on_container_move_assignment::value) { - my_allocator = other.my_allocator; - } + tbb::detail::copy_assign_allocators(my_allocator, other.my_allocator); my_queue_representation->assign(*other.my_queue_representation, my_allocator, copy_construct_item); return *this; } @@ -437,7 +428,7 @@ class concurrent_bounded_queue { return *this; clear(); if (queue_allocator_traits::propagate_on_container_move_assignment::value) { - my_allocator = std::move(other.my_allocator); + tbb::detail::move_assign_allocators(my_allocator, other.my_allocator); internal_swap(other); } else { if (my_allocator == other.my_allocator) { @@ -467,12 +458,7 @@ class concurrent_bounded_queue { } void swap ( concurrent_bounded_queue& other ) { - if (queue_allocator_traits::propagate_on_container_swap::value) { - using std::swap; - swap(my_allocator, other.my_allocator); - } else { - __TBB_ASSERT(my_allocator == other.my_allocator, "unequal allocators"); - } + tbb::detail::swap_allocators(my_allocator, other.my_allocator); internal_swap(other); } diff --git a/include/oneapi/tbb/detail/_allocator_traits.h b/include/oneapi/tbb/detail/_allocator_traits.h index 8c60e25e7e..c5575ab336 100644 --- a/include/oneapi/tbb/detail/_allocator_traits.h +++ b/include/oneapi/tbb/detail/_allocator_traits.h @@ -91,7 +91,10 @@ void swap_allocators_impl( Allocator& lhs, Allocator& rhs, /*pocs = */ std::true } template -void swap_allocators_impl( Allocator&, Allocator&, /*pocs = */ std::false_type ) {} +void swap_allocators_impl( Allocator& lhs, Allocator& rhs, /*pocs = */ std::false_type ) { + // If the lhs and rhs are not equal, the behavior is undefined + __TBB_ASSERT(lhs == rhs, "unequal allocators"); +} // Swaps allocators only if propagate_on_container_swap is true template