storage: insert for empty types always appends elements

This commit is contained in:
Michele Caini
2022-01-13 14:05:33 +01:00
parent ecadee3876
commit 9eba103de9
2 changed files with 13 additions and 13 deletions

View File

@@ -852,17 +852,17 @@ public:
* @tparam Args Types of optional arguments.
* @param first An iterator to the first element of the range of entities.
* @param last An iterator past the last element of the range of entities.
* @param args Parameters to use to construct an object for the entity.
*/
template<typename It, typename... Args>
void insert(It first, It last, Args &&...) {
for(const auto sz = base_type::size(); first != last && base_type::slot() != sz; ++first) {
emplace(*first);
}
base_type::reserve(base_type::size() + std::distance(first, last));
for(; first != last; ++first) {
emplace(*first);
if constexpr(std::is_invocable_v<decltype(&base_type::try_insert), base_type &, It, It>) {
base_type::try_insert(first, last);
} else {
for(; first != last; ++first) {
entity_type curr[1u]{*first};
base_type::try_insert(curr, curr + 1u);
}
}
}

View File

@@ -310,11 +310,11 @@ TEST(Storage, InsertEmptyType) {
const empty_stable_type values[2u]{};
pool.insert(std::rbegin(entities), std::rend(entities), std::begin(values));
ASSERT_EQ(pool.size(), 2u);
ASSERT_EQ(pool.at(0u), entities[0u]);
ASSERT_EQ(pool.at(1u), entities[1u]);
ASSERT_EQ(pool.index(entities[0u]), 0u);
ASSERT_EQ(pool.index(entities[1u]), 1u);
ASSERT_EQ(pool.size(), 4u);
ASSERT_EQ(pool.at(2u), entities[1u]);
ASSERT_EQ(pool.at(3u), entities[0u]);
ASSERT_EQ(pool.index(entities[0u]), 3u);
ASSERT_EQ(pool.index(entities[1u]), 2u);
}
TEST(Storage, Erase) {