diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index d29be0c77..d0d8c9d8e 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -104,23 +104,20 @@ private: template void unroll(choice_t<0>) {} - template - void assign(Key &&key, Value &&... value) { - static meta_any property[1u + sizeof...(Value)]{}; + template + void assign(Key &&key, meta_any value = {}) { + static meta_any property[2u]{}; static internal::meta_prop_node node{ nullptr, property, - sizeof...(Value) ? property + 1u : nullptr + property + 1u }; entt::meta_any instance{std::forward(key)}; ENTT_ASSERT(!internal::find_if_not(&instance, *curr, &node)); property[0u] = std::move(instance); - - if constexpr(sizeof...(Value) > 0) { - property[1u] = (std::forward(value), ...); - } + property[1u] = std::move(value); if(!internal::find_if(&node, *curr)) { node.next = *curr; diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 606a839b2..6e0fb1e5b 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -659,7 +659,7 @@ struct meta_prop { * @return A meta any containing the value stored with the property. */ [[nodiscard]] meta_any value() const { - return node->value ? *node->value : meta_any{}; + return *node->value; } /** diff --git a/test/entt/meta/meta_prop.cpp b/test/entt/meta/meta_prop.cpp index 81d338b2b..790c130c0 100644 --- a/test/entt/meta/meta_prop.cpp +++ b/test/entt/meta/meta_prop.cpp @@ -62,10 +62,25 @@ TEST_F(MetaProp, FromBase) { } TEST_F(MetaProp, ReRegistration) { + using namespace entt::literals; + MetaProp::StaticSetUp(); - auto *node = entt::internal::meta_info::resolve(); + auto *node = entt::internal::meta_info::resolve(); + auto type = entt::resolve(); ASSERT_NE(node->prop, nullptr); ASSERT_EQ(node->prop->next, nullptr); + + ASSERT_TRUE(type.prop("int"_hs)); + ASSERT_EQ(type.prop("int"_hs).value().cast(), 42); + + entt::meta().prop("double"_hs, 3.); + + ASSERT_NE(node->prop, nullptr); + ASSERT_EQ(node->prop->next, nullptr); + + ASSERT_FALSE(type.prop("int"_hs)); + ASSERT_TRUE(type.prop("double"_hs)); + ASSERT_EQ(type.prop("double"_hs).value().cast(), 3.); }