diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index 5216b6070..3e3df2c85 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -74,11 +74,13 @@ class basic_registry { } template - std::enable_if_t::value_type, Entity>, typename storage::reverse_iterator_type> + std::enable_if_t::value_type, Entity>, void> assign(basic_registry &owner, It first, It last) { - auto it = this->construct(first, last); - std::for_each(first, last, [this, &owner](const auto entt) { construction.publish(entt, owner); }); - return it; + this->construct(first, last); + + if(!construction.empty()) { + std::for_each(first, last, [this, &owner](const auto entt) { construction.publish(entt, owner); }); + } } void remove(basic_registry &owner, const Entity entt) { @@ -641,13 +643,12 @@ public: * @tparam It Type of input iterator. * @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. - * @return An iterator to the list of components just created. */ template - std::enable_if_t::value_type, entity_type>, typename pool_handler::reverse_iterator_type> + std::enable_if_t::value_type, entity_type>, void> assign(It first, It last) { ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); })); - return assure().assign(*this, first, last); + assure().assign(*this, first, last); } /** diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index c4e4e58f5..81f346c9e 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -164,8 +164,6 @@ public: using iterator_type = iterator; /*! @brief Constant random access iterator type. */ using const_iterator_type = iterator; - /*! @brief Reverse iterator type. */ - using reverse_iterator_type = std::reverse_iterator>; /** * @brief Increases the capacity of a storage. @@ -345,16 +343,13 @@ public: * @tparam It Type of forward iterator. * @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. - * @return An iterator to the list of instances just created and sorted the - * same of the entities. */ template - std::enable_if_t::value_type, entity_type>, reverse_iterator_type> + std::enable_if_t::value_type, entity_type>, void> construct(It first, It last) { - instances.insert(instances.end(), std::distance(first, last), object_type{}); + instances.resize(instances.size() + std::distance(first, last), object_type{}); // entity goes after component in case constructor throws underlying_type::construct(first, last); - return std::make_reverse_iterator(begin() + std::distance(first, last)); } /** @@ -581,8 +576,6 @@ public: using size_type = std::size_t; /*! @brief Random access iterator type. */ using iterator_type = iterator; - /*! @brief Reverse iterator type. */ - using reverse_iterator_type = std::reverse_iterator; /** * @brief Returns an iterator to the beginning. @@ -679,14 +672,11 @@ public: * @tparam It Type of forward iterator. * @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. - * @return An iterator to the list of instances just created and sorted the - * same of the entities. */ template - std::enable_if_t::value_type, entity_type>, reverse_iterator_type> + std::enable_if_t::value_type, entity_type>, void> construct(It first, It last) { underlying_type::construct(first, last); - return std::make_reverse_iterator(begin() + std::distance(first, last)); } /*! @copydoc storage::sort */ diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index 14daf68ce..24fbc4f58 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -1191,17 +1191,11 @@ TEST(Registry, RangeAssign) { ASSERT_FALSE(registry.has(e2)); const auto view = registry.view(); - auto it = registry.assign(view.begin(), view.end()); + registry.assign(view.begin(), view.end()); ASSERT_TRUE(registry.has(e0)); ASSERT_TRUE(registry.has(e1)); ASSERT_FALSE(registry.has(e2)); - - *it = 0.f; - *(it+1) = 1.f; - - ASSERT_EQ(registry.get(*view.begin()), 0.f); - ASSERT_EQ(registry.get(*(++view.begin())), 1.f); } TEST(Registry, RangeRemove) { diff --git a/test/entt/entity/storage.cpp b/test/entt/entity/storage.cpp index bd86b868e..6c7ec381a 100644 --- a/test/entt/entity/storage.cpp +++ b/test/entt/entity/storage.cpp @@ -100,7 +100,7 @@ TEST(Storage, BatchAdd) { entities[0] = entt::entity{3}; entities[1] = entt::entity{42}; - auto it = pool.construct(std::begin(entities), std::end(entities)); + pool.construct(std::begin(entities), std::end(entities)); ASSERT_TRUE(pool.has(entities[0])); ASSERT_TRUE(pool.has(entities[1])); @@ -109,12 +109,6 @@ TEST(Storage, BatchAdd) { ASSERT_EQ(pool.size(), 2u); ASSERT_EQ(pool.get(entities[0]), 0); ASSERT_EQ(pool.get(entities[1]), 0); - - it[0] = 1; - it[1] = 2; - - ASSERT_EQ(pool.get(entities[0]), 1); - ASSERT_EQ(pool.get(entities[1]), 2); } TEST(Storage, BatchAddEmptyType) {