storage: generalized ::insert for all mixins

This commit is contained in:
Michele Caini
2021-08-26 17:14:51 +02:00
parent 23d162e9e4
commit dc5488a198
2 changed files with 16 additions and 10 deletions

View File

@@ -820,19 +820,15 @@ public:
}
/**
* @brief Assigns one or more entities to a storage.
*
* @warning
* Attempting to assign an entity that already belongs to the storage
* results in undefined behavior.
*
* @brief Assigns entities to a storage.
* @tparam It Type of input iterator.
* @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.
*/
template<typename It>
void insert(It first, It last, const value_type & = {}) {
base_type::insert(first, last);
template<typename It, typename... Args>
void insert(It first, It last, Args &&...) {
base_type::insert(std::move(first), std::move(last));
}
};
@@ -877,7 +873,7 @@ struct storage_adapter_mixin: Type {
*/
template<typename It, typename... Args>
void insert(basic_registry<entity_type> &, It first, It last, Args &&... args) {
Type::insert(first, last, std::forward<Args>(args)...);
Type::insert(std::move(first), std::move(last), std::forward<Args>(args)...);
}
/**

View File

@@ -248,6 +248,16 @@ TEST(Storage, InsertEmptyType) {
ASSERT_FALSE(pool.empty());
ASSERT_EQ(pool.size(), 2u);
pool.erase(std::begin(entities), std::end(entities));
const empty_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[1u]);
ASSERT_EQ(pool.at(1u), entities[0u]);
ASSERT_EQ(pool.index(entities[0u]), 1u);
ASSERT_EQ(pool.index(entities[1u]), 0u);
}
TEST(Storage, Erase) {