storage: emplace returns the newly created object
This commit is contained in:
@@ -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<typename... Args>
|
||||
void emplace(const entity_type entt, Args &&... args) {
|
||||
object_type & emplace(const entity_type entt, Args &&... args) {
|
||||
if constexpr(std::is_aggregate_v<object_type>) {
|
||||
instances.push_back(Type{std::forward<Args>(args)...});
|
||||
} else {
|
||||
@@ -369,6 +370,7 @@ public:
|
||||
|
||||
// entity goes after component in case constructor throws
|
||||
underlying_type::emplace(entt);
|
||||
return instances.back();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -159,8 +159,7 @@ TEST(Storage, AggregatesMustWork) {
|
||||
TEST(Storage, TypesFromStandardTemplateLibraryMustWork) {
|
||||
// see #37 - this test shouldn't crash, that's all
|
||||
entt::storage<std::unordered_set<int>> 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});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user