dense_set: strong exception guarantee (emplace/insert)
This commit is contained in:
@@ -275,8 +275,8 @@ class dense_set {
|
||||
return std::make_pair(it, false);
|
||||
}
|
||||
|
||||
const auto next = std::exchange(sparse.first()[index], packed.first().size());
|
||||
packed.first().emplace_back(next, std::forward<Other>(value));
|
||||
packed.first().emplace_back(sparse.first()[index], std::forward<Other>(value));
|
||||
sparse.first()[index] = packed.first().size() - 1u;
|
||||
rehash_if_required();
|
||||
|
||||
return std::make_pair(--end(), true);
|
||||
|
||||
@@ -832,6 +832,21 @@ TEST(DenseSet, ThrowingAllocator) {
|
||||
ASSERT_EQ(set.bucket_count(), minimum_bucket_count);
|
||||
ASSERT_THROW(set.reserve(2u * set.bucket_count()), packed_exception);
|
||||
ASSERT_EQ(set.bucket_count(), minimum_bucket_count);
|
||||
|
||||
packed_allocator::trigger_on_allocate = true;
|
||||
|
||||
ASSERT_THROW(set.emplace(), packed_exception);
|
||||
ASSERT_FALSE(set.contains(0u));
|
||||
|
||||
packed_allocator::trigger_on_allocate = true;
|
||||
|
||||
ASSERT_THROW(set.emplace(std::size_t{}), packed_exception);
|
||||
ASSERT_FALSE(set.contains(0u));
|
||||
|
||||
packed_allocator::trigger_on_allocate = true;
|
||||
|
||||
ASSERT_THROW(set.insert(0u), packed_exception);
|
||||
ASSERT_FALSE(set.contains(0u));
|
||||
}
|
||||
|
||||
#if defined(ENTT_HAS_TRACKED_MEMORY_RESOURCE)
|
||||
|
||||
Reference in New Issue
Block a user