diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index 71bfbeef8..af4216d56 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -82,8 +82,9 @@ class basic_registry { std::enable_if_t::value_type, Entity>, typename storage::reverse_iterator_type> assign(basic_registry &owner, It first, It last, Args &&... args) { auto it = storage::construct(first, last, std::forward(args)...); + const auto end = it + (!construction.empty() * std::distance(first, last)); - std::for_each_n(it, !construction.empty() * std::distance(first, last), [this, &owner, &first](decltype(*it) component) { + std::for_each(it, end, [this, &owner, &first](decltype(*it) component) { construction.publish(*(first++), owner, component); });