Browse Source

meta: introduce meta_ctx_arg[_t]

Michele Caini 3 years ago
parent
commit
d61dff45c1
3 changed files with 12 additions and 6 deletions
  1. 6 0
      src/entt/meta/context.hpp
  2. 4 4
      src/entt/meta/meta.hpp
  3. 2 2
      src/entt/meta/node.hpp

+ 6 - 0
src/entt/meta/context.hpp

@@ -32,6 +32,12 @@ struct meta_context {
  * @endcond
  * @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. */
 /*! @brief Opaque meta context type. */
 class meta_ctx: private internal::meta_context {
 class meta_ctx: private internal::meta_context {
     /*! @brief Attorney idiom like model to access the base class. */
     /*! @brief Attorney idiom like model to access the base class. */

+ 4 - 4
src/entt/meta/meta.hpp

@@ -196,13 +196,13 @@ class meta_any {
 public:
 public:
     /*! Default constructor. */
     /*! Default constructor. */
     meta_any() noexcept
     meta_any() noexcept
-        : meta_any{locator<meta_ctx>::value_or()} {}
+        : meta_any{meta_ctx_arg, locator<meta_ctx>::value_or()} {}
 
 
     /**
     /**
      * @brief Context aware constructor.
      * @brief Context aware constructor.
      * @param area The context from which to search for meta types.
      * @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{},
         : storage{},
           ctx{&area},
           ctx{&area},
           node{},
           node{},
@@ -226,7 +226,7 @@ public:
      * @tparam Type Type of object to use to initialize the wrapper.
      * @tparam Type Type of object to use to initialize the wrapper.
      * @param value An instance of an object to use to initialize the wrapper.
      * @param value An instance of an object to use to initialize the wrapper.
      */
      */
-    template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, meta_any> && !std::is_same_v<std::decay_t<Type>, meta_ctx>>>
+    template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, meta_any>>>
     meta_any(Type &&value)
     meta_any(Type &&value)
         : meta_any{std::in_place_type<std::decay_t<Type>>, std::forward<Type>(value)} {}
         : meta_any{std::in_place_type<std::decay_t<Type>>, std::forward<Type>(value)} {}
 
 
@@ -586,7 +586,7 @@ meta_any make_meta(Args &&...args) {
 template<typename Type>
 template<typename Type>
 meta_any forward_as_meta(const meta_ctx &ctx, Type &&value) {
 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
     // 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<Type &&>(std::forward<Type>(value));
     elem.emplace<Type &&>(std::forward<Type>(value));
     return elem;
     return elem;
 }
 }

+ 2 - 2
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<Type>) {
     if constexpr(std::is_default_constructible_v<Type>) {
         node.default_constructor = +[](const meta_ctx &ctx) {
         node.default_constructor = +[](const meta_ctx &ctx) {
             // TODO it would be great if we had value and context construction support for meta_any
             // 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<Type>();
             elem.emplace<Type>();
             return elem;
             return elem;
         };
         };
@@ -199,7 +199,7 @@ void meta_from_void([[maybe_unused]] meta_type_node &node) {
     if constexpr(!std::is_same_v<Type, void> && !std::is_function_v<Type>) {
     if constexpr(!std::is_same_v<Type, void> && !std::is_function_v<Type>) {
         node.from_void = +[](const meta_ctx &ctx, void *element, const void *as_const) {
         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
             // 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<std::decay_t<Type> &>(*static_cast<std::decay_t<Type> *>(element)) : elem.emplace<const std::decay_t<Type> &>(*static_cast<const std::decay_t<Type> *>(as_const));
             element ? elem.emplace<std::decay_t<Type> &>(*static_cast<std::decay_t<Type> *>(element)) : elem.emplace<const std::decay_t<Type> &>(*static_cast<const std::decay_t<Type> *>(as_const));
             return elem;
             return elem;
         };
         };