diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index b57d626d4..08c1e1480 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -1407,16 +1407,11 @@ public: handler->current.construct(entity); } } else { - const auto &cpool = std::min({ - static_cast &>(std::get> &>(cpools))..., - static_cast &>(std::get> &>(cpools))... - }, [](const auto &lhs, const auto &rhs) { - return lhs.size() < rhs.size(); - }); + const auto curr = view(exclude); // we cannot iterate backwards because we want to leave behind valid entities in case of owned types - std::for_each(std::make_reverse_iterator(cpool.end()), std::make_reverse_iterator(cpool.begin()), [cpools, handler, curr = view(entt::exclude)](const auto entity) { - if(const auto pos = handler->current; curr.contains(entity) && !(std::get<0>(cpools).index(entity) < ++handler->current)) { + std::for_each(std::make_reverse_iterator(curr.end()), std::make_reverse_iterator(curr.begin()), [cpools, handler](const auto entity) { + if(const auto pos = handler->current; !(std::get<0>(cpools).index(entity) < ++handler->current)) { (std::get> &>(cpools).swap(std::get> &>(cpools).data()[pos], entity), ...); } });