diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index e32fd70da..c2bea0de2 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -767,6 +767,19 @@ public: return allocator_type{base_type::get_allocator()}; } + /** + * @brief Returns the object assigned to an entity, that is `void`. + * + * @warning + * Attempting to use an entity that doesn't belong to the storage results in + * undefined behavior. + * + * @param entt A valid identifier. + */ + void get([[maybe_unused]] const entity_type entt) const ENTT_NOEXCEPT { + ENTT_ASSERT(base_type::contains(entt), "Storage does not contain entity"); + } + /** * @brief Returns an empty tuple. * @@ -992,10 +1005,7 @@ public: decltype(auto) emplace(basic_registry &owner, const entity_type entt, Args &&... args) { Type::emplace(entt, std::forward(args)...); construction.publish(owner, entt); - - if constexpr(!ignore_as_empty_v) { - return this->get(entt); - } + return this->get(entt); } /** @@ -1032,10 +1042,7 @@ public: decltype(auto) patch(basic_registry &owner, const entity_type entt, Func &&... func) { Type::patch(entt, std::forward(func)...); update.publish(owner, entt); - - if constexpr(!ignore_as_empty_v) { - return this->get(entt); - } + return this->get(entt); } private: diff --git a/test/entt/entity/storage.cpp b/test/entt/entity/storage.cpp index 9c700e19d..73c887630 100644 --- a/test/entt/entity/storage.cpp +++ b/test/entt/entity/storage.cpp @@ -208,6 +208,7 @@ TEST(Storage, EmptyType) { ASSERT_NO_THROW([[maybe_unused]] auto alloc = pool.get_allocator()); ASSERT_TRUE(pool.contains(entt::entity{99})); + ASSERT_DEATH(pool.get(entt::entity{}), ""); } TEST(Storage, Insert) {