diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 9c764b21f..898f8ee25 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -358,9 +358,10 @@ public: * @tparam Args Types of arguments to use to construct the object. * @param entt A valid entity identifier. * @param args Parameters to use to construct an object for the entity. + * @return A reference to the newly created object. */ template - void emplace(const entity_type entt, Args &&... args) { + object_type & emplace(const entity_type entt, Args &&... args) { if constexpr(std::is_aggregate_v) { instances.push_back(Type{std::forward(args)...}); } else { @@ -369,6 +370,7 @@ public: // entity goes after component in case constructor throws underlying_type::emplace(entt); + return instances.back(); } /** diff --git a/test/entt/entity/storage.cpp b/test/entt/entity/storage.cpp index 3fbd834a5..57a8c34c9 100644 --- a/test/entt/entity/storage.cpp +++ b/test/entt/entity/storage.cpp @@ -159,8 +159,7 @@ TEST(Storage, AggregatesMustWork) { TEST(Storage, TypesFromStandardTemplateLibraryMustWork) { // see #37 - this test shouldn't crash, that's all entt::storage> pool; - pool.emplace(entt::entity{0}); - pool.get(entt::entity{0}).insert(42); + pool.emplace(entt::entity{0}).insert(42); pool.erase(entt::entity{0}); }