diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index d1cbc8712..2a36eec3d 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -187,21 +187,40 @@ class basic_registry { template const pool_handler & assure() const { static_assert(std::is_same_v>); - const auto index = type_index::value(); - if(!(index < pools.size())) { - pools.resize(index+1); + if constexpr(has_type_index_v) { + const auto index = type_index::value(); + + if(!(index < pools.size())) { + pools.resize(index+1); + } + + if(auto &&cpool = pools[index]; !cpool.pool) { + cpool.type_id = type_info::id(); + cpool.pool.reset(new pool_handler()); + cpool.remove = [](sparse_set &cpool, basic_registry &owner, const entity_type entt) { + static_cast &>(cpool).remove(owner, entt); + }; + } + + return static_cast &>(*pools[index].pool); + } else { + sparse_set *cpool{nullptr}; + + if(auto it = std::find_if(pools.begin(), pools.end(), [id = type_info::id()](const auto &pdata) { return id == pdata.type_id; }); it == pools.cend()) { + cpool = pools.emplace_back(pool_data{ + type_info::id(), + std::unique_ptr>{new pool_handler()}, + [](sparse_set &cpool, basic_registry &owner, const entity_type entt) { + static_cast &>(cpool).remove(owner, entt); + } + }).pool.get(); + } else { + cpool = it->pool.get(); + } + + return static_cast &>(*cpool); } - - if(auto &&cpool = pools[index]; !cpool.pool) { - cpool.type_id = type_info::id(); - cpool.pool.reset(new pool_handler()); - cpool.remove = [](sparse_set &cpool, basic_registry &owner, const entity_type entt) { - static_cast &>(cpool).remove(owner, entt); - }; - } - - return static_cast &>(*pools[index].pool); } template