forked from boostorg/unordered
Fix fca allocator swapping, and test that pmr allocator swap compiles
This commit is contained in:
@ -659,12 +659,7 @@ namespace boost {
|
|||||||
std::swap(buckets, other.buckets);
|
std::swap(buckets, other.buckets);
|
||||||
std::swap(groups, other.groups);
|
std::swap(groups, other.groups);
|
||||||
|
|
||||||
bool b = boost::allocator_propagate_on_container_swap<
|
swap_allocator_if_pocs(other);
|
||||||
allocator_type>::type::value;
|
|
||||||
if (b) {
|
|
||||||
boost::core::invoke_swap(
|
|
||||||
get_node_allocator(), other.get_node_allocator());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node_allocator_type const& get_node_allocator() const
|
node_allocator_type const& get_node_allocator() const
|
||||||
@ -876,6 +871,27 @@ namespace boost {
|
|||||||
pbg->prev->next = pbg->next;
|
pbg->prev->next = pbg->next;
|
||||||
pbg->prev = pbg->next = group_pointer();
|
pbg->prev = pbg->next = group_pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void swap_allocator_if_pocs(grouped_bucket_array& other)
|
||||||
|
{
|
||||||
|
using allocator_pocs =
|
||||||
|
typename boost::allocator_propagate_on_container_swap<
|
||||||
|
allocator_type>::type;
|
||||||
|
swap_allocator_if_pocs(
|
||||||
|
other, std::integral_constant<bool, allocator_pocs::value>());
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap_allocator_if_pocs(
|
||||||
|
grouped_bucket_array& other, std::true_type /* propagate */)
|
||||||
|
{
|
||||||
|
boost::core::invoke_swap(
|
||||||
|
get_node_allocator(), other.get_node_allocator());
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap_allocator_if_pocs(
|
||||||
|
grouped_bucket_array&, std::false_type /* don't propagate */)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace unordered
|
} // namespace unordered
|
||||||
|
@ -180,6 +180,7 @@ namespace pmr_allocator_tests {
|
|||||||
{
|
{
|
||||||
copy_op,
|
copy_op,
|
||||||
move_op,
|
move_op,
|
||||||
|
swap_op,
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class X> void do_operation(X& x1, X& x2, operation op)
|
template <class X> void do_operation(X& x1, X& x2, operation op)
|
||||||
@ -191,6 +192,9 @@ namespace pmr_allocator_tests {
|
|||||||
case move_op:
|
case move_op:
|
||||||
x2 = std::move(x1);
|
x2 = std::move(x1);
|
||||||
return;
|
return;
|
||||||
|
case swap_op:
|
||||||
|
x1.swap(x1); // Swapping with non-equal non-pocs allocators is UB
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
BOOST_TEST(false);
|
BOOST_TEST(false);
|
||||||
}
|
}
|
||||||
@ -231,7 +235,7 @@ namespace pmr_allocator_tests {
|
|||||||
UNORDERED_TEST(
|
UNORDERED_TEST(
|
||||||
pmr_no_propagate_on_operation,
|
pmr_no_propagate_on_operation,
|
||||||
PMR_ALLOCATOR_TESTS_ARGS
|
PMR_ALLOCATOR_TESTS_ARGS
|
||||||
((copy_op)(move_op))
|
((copy_op)(move_op)(swap_op))
|
||||||
)
|
)
|
||||||
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
Reference in New Issue
Block a user