From d61dff45c11901655d9b2608fbbd10adfeb7f51f Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 10 Oct 2022 13:00:20 +0200 Subject: [PATCH] meta: introduce meta_ctx_arg[_t] --- src/entt/meta/context.hpp | 6 ++++++ src/entt/meta/meta.hpp | 8 ++++---- src/entt/meta/node.hpp | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/entt/meta/context.hpp b/src/entt/meta/context.hpp index 2b59831a0..d9ea62296 100644 --- a/src/entt/meta/context.hpp +++ b/src/entt/meta/context.hpp @@ -32,6 +32,12 @@ struct meta_context { * @endcond */ +/*! @brief Disambiguation tag for constructors and the like. */ +class meta_ctx_arg_t final {}; + +/*! @brief Constant of type meta_context_arg_t used to disambiguate calls. */ +inline constexpr meta_ctx_arg_t meta_ctx_arg{}; + /*! @brief Opaque meta context type. */ class meta_ctx: private internal::meta_context { /*! @brief Attorney idiom like model to access the base class. */ diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index a6acbd3d2..be5015bda 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -196,13 +196,13 @@ class meta_any { public: /*! Default constructor. */ meta_any() noexcept - : meta_any{locator::value_or()} {} + : meta_any{meta_ctx_arg, locator::value_or()} {} /** * @brief Context aware constructor. * @param area The context from which to search for meta types. */ - meta_any(const meta_ctx &area) noexcept + meta_any(meta_ctx_arg_t, const meta_ctx &area) noexcept : storage{}, ctx{&area}, node{}, @@ -226,7 +226,7 @@ public: * @tparam Type Type of object to use to initialize the wrapper. * @param value An instance of an object to use to initialize the wrapper. */ - template, meta_any> && !std::is_same_v, meta_ctx>>> + template, meta_any>>> meta_any(Type &&value) : meta_any{std::in_place_type>, std::forward(value)} {} @@ -586,7 +586,7 @@ meta_any make_meta(Args &&...args) { template meta_any forward_as_meta(const meta_ctx &ctx, Type &&value) { // TODO it would be great if we had value and context construction support for meta_any - meta_any elem{ctx}; + meta_any elem{meta_ctx_arg, ctx}; elem.emplace(std::forward(value)); return elem; } diff --git a/src/entt/meta/node.hpp b/src/entt/meta/node.hpp index 51aac7bab..5ebbec54e 100644 --- a/src/entt/meta/node.hpp +++ b/src/entt/meta/node.hpp @@ -174,7 +174,7 @@ void meta_default_constructor([[maybe_unused]] meta_type_node &node) { if constexpr(std::is_default_constructible_v) { node.default_constructor = +[](const meta_ctx &ctx) { // TODO it would be great if we had value and context construction support for meta_any - meta_any elem{ctx}; + meta_any elem{meta_ctx_arg, ctx}; elem.emplace(); return elem; }; @@ -199,7 +199,7 @@ void meta_from_void([[maybe_unused]] meta_type_node &node) { if constexpr(!std::is_same_v && !std::is_function_v) { node.from_void = +[](const meta_ctx &ctx, void *element, const void *as_const) { // TODO it would be great if we had value and context construction support for meta_any - meta_any elem{ctx}; + meta_any elem{meta_ctx_arg, ctx}; element ? elem.emplace &>(*static_cast *>(element)) : elem.emplace &>(*static_cast *>(as_const)); return elem; };