From e3e84490e5c61d620d0a8b211b2a2610def3b1db Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Fri, 28 Feb 2025 08:37:32 +0100 Subject: [PATCH] meta: rebind meta_any with context(ctx) --- TODO | 1 + src/entt/meta/meta.hpp | 10 ++++++++++ test/entt/meta/meta_any.cpp | 8 ++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 1fed0569c..e5eea1a7f 100644 --- a/TODO +++ b/TODO @@ -35,3 +35,4 @@ TODO: * any cdynamic to support const ownership construction * allow passing arguments to meta setter/getter (we can fallback on meta invoke probably) * meta: review/update rebind policy for handles and arguments +* meta: deprecate rebinding ctors for meta any/handle diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 58c1ad07b..d7758be08 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -650,6 +650,16 @@ class meta_any { return *ctx; } + /** + * @brief Returns the underlying meta context. + * @return The underlying meta context. + */ + void context(const meta_ctx &area) noexcept { + if(ctx = &area; node.resolve != nullptr) { + node = node.resolve(internal::meta_context::from(*ctx)); + } + } + private: any storage; const meta_ctx *ctx{&locator::value_or()}; diff --git a/test/entt/meta/meta_any.cpp b/test/entt/meta/meta_any.cpp index 9227c7a09..d448895e8 100644 --- a/test/entt/meta/meta_any.cpp +++ b/test/entt/meta/meta_any.cpp @@ -137,14 +137,18 @@ TEST_F(MetaAny, Empty) { } TEST_F(MetaAny, Context) { - entt::meta_any any{}; + using namespace entt::literals; + + entt::meta_any any{std::in_place_type}; const entt::meta_ctx ctx{}; + ASSERT_TRUE(any.type().data("value"_hs)); ASSERT_EQ(&any.context(), &entt::locator::value_or()); ASSERT_NE(&any.context(), &ctx); - any = entt::meta_any{entt::meta_ctx_arg, ctx}; + any.context(ctx); + ASSERT_FALSE(any.type().data("value"_hs)); ASSERT_NE(&any.context(), &entt::locator::value_or()); ASSERT_EQ(&any.context(), &ctx); }