Add strong exception guarantees around Hash, KeyEqual for move_assign_exception_tests

This commit is contained in:
Christian Mazakas
2022-12-01 15:50:28 -08:00
parent 260b573d8d
commit 2043f98593

View File

@ -20,6 +20,7 @@ template <class T> struct move_assign_base : public test::exception_base
{
test::random_values<T> x_values, y_values;
T x, y;
int t1, t2;
typedef typename T::hasher hasher;
typedef typename T::key_equal key_equal;
@ -28,7 +29,9 @@ template <class T> struct move_assign_base : public test::exception_base
move_assign_base(int tag1, int tag2, float mlf1 = 1.0, float mlf2 = 1.0)
: x_values(), y_values(),
x(0, hasher(tag1), key_equal(tag1), allocator_type(tag1)),
y(0, hasher(tag2), key_equal(tag2), allocator_type(tag2))
y(0, hasher(tag2), key_equal(tag2), allocator_type(tag2)),
t1(tag1),
t2(tag2)
{
x.max_load_factor(mlf1);
y.max_load_factor(mlf2);
@ -52,6 +55,22 @@ template <class T> struct move_assign_base : public test::exception_base
{
test::check_equivalent_keys(x1);
if (x1.hash_function() == hasher(t1)) {
BOOST_TEST(x1.key_eq() == key_equal(t1));
}
if (x1.hash_function() == hasher(t2)) {
BOOST_TEST(x1.key_eq() == key_equal(t2));
}
if (x1.key_eq() == key_equal(t1)) {
BOOST_TEST(x1.hash_function() == hasher(t1));
}
if (x1.key_eq() == key_equal(t2)) {
BOOST_TEST(x1.hash_function() == hasher(t2));
}
// If the container is empty at the point of the exception, the
// internal structure is hidden, this exposes it, at the cost of
// messing up the data.