dense_map: fix an issue when erasing movable keys
This commit is contained in:
@@ -331,8 +331,8 @@ class dense_map {
|
||||
|
||||
void move_and_pop(const std::size_t pos) {
|
||||
if(const auto last = size() - 1u; pos != last) {
|
||||
packed.first()[pos] = std::move(packed.first().back());
|
||||
size_type *curr = sparse.first().data() + key_to_bucket(packed.first().back().element.first);
|
||||
packed.first()[pos] = std::move(packed.first().back());
|
||||
for(; *curr != last; curr = &packed.first()[*curr].next) {}
|
||||
*curr = pos;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
@@ -788,6 +789,24 @@ TEST(DenseMap, Erase) {
|
||||
ASSERT_EQ(map.size(), 0u);
|
||||
}
|
||||
|
||||
TEST(DenseMap, EraseWithMovableKeyValue) {
|
||||
static constexpr std::size_t minimum_bucket_count = 8u;
|
||||
entt::dense_map<std::string, std::size_t> map;
|
||||
|
||||
map.emplace("0", 0u);
|
||||
map.emplace("1", 1u);
|
||||
|
||||
ASSERT_EQ(map.bucket_count(), minimum_bucket_count);
|
||||
ASSERT_EQ(map.size(), 2u);
|
||||
|
||||
auto it = map.erase(map.find("0"));
|
||||
|
||||
ASSERT_EQ(it->first, "1");
|
||||
ASSERT_EQ(it->second, 1u);
|
||||
ASSERT_EQ(map.size(), 1u);
|
||||
ASSERT_FALSE(map.contains("0"));
|
||||
}
|
||||
|
||||
TEST(DenseMap, EraseFromBucket) {
|
||||
static constexpr std::size_t minimum_bucket_count = 8u;
|
||||
entt::dense_map<std::size_t, std::size_t, entt::identity> map;
|
||||
|
||||
Reference in New Issue
Block a user