registry: add support for non-existent pools to try_get

This commit is contained in:
Michele Caini
2023-05-02 14:37:06 +02:00
parent 912cb2ad54
commit 34f6a747a8

View File

@@ -1048,8 +1048,8 @@ public:
template<typename... Type>
[[nodiscard]] auto try_get([[maybe_unused]] const entity_type entt) const {
if constexpr(sizeof...(Type) == 1u) {
const auto &cpool = assure<std::remove_const_t<Type>...>();
return cpool->contains(entt) ? std::addressof(cpool->get(entt)) : nullptr;
const auto *cpool = assure<std::remove_const_t<Type>...>();
return (cpool && cpool->contains(entt)) ? std::addressof(cpool->get(entt)) : nullptr;
} else {
return std::make_tuple(try_get<Type>(entt)...);
}
@@ -1059,7 +1059,8 @@ public:
template<typename... Type>
[[nodiscard]] auto try_get([[maybe_unused]] const entity_type entt) {
if constexpr(sizeof...(Type) == 1u) {
return (const_cast<Type *>(std::as_const(*this).template try_get<Type>(entt)), ...);
auto &cpool = assure<std::remove_const_t<Type>...>();
return (static_cast<Type *>(cpool.contains(entt) ? std::addressof(cpool.get(entt)) : nullptr), ...);
} else {
return std::make_tuple(try_get<Type>(entt)...);
}