Browse Source

meta: improved meta_handle support to meta_any

skypjack 5 months ago
parent
commit
4debb79a60
1 changed files with 12 additions and 17 deletions
  1. 12 17
      src/entt/meta/meta.hpp

+ 12 - 17
src/entt/meta/meta.hpp

@@ -649,7 +649,16 @@ template<typename Type>
 }
 }
 
 
 /*! @brief Opaque pointers to instances of any type. */
 /*! @brief Opaque pointers to instances of any type. */
-struct meta_handle {
+class meta_handle {
+    template<typename Type, typename = std::enable_if_t<std::is_same_v<std::decay_t<Type>, meta_any>>>
+    meta_handle(int, const meta_ctx &ctx, Type &value)
+        : any{ctx, value.as_ref()} {}
+
+    template<typename Type>
+    meta_handle(char, const meta_ctx &ctx, Type &value)
+        : any{ctx, std::in_place_type<Type &>, value} {}
+
+public:
     /*! Default constructor. */
     /*! Default constructor. */
     [[deprecated("not necessary, use direct contructors instead")]]
     [[deprecated("not necessary, use direct contructors instead")]]
     meta_handle() = default;
     meta_handle() = default;
@@ -662,20 +671,6 @@ struct meta_handle {
     meta_handle(meta_ctx_arg_t, const meta_ctx &area)
     meta_handle(meta_ctx_arg_t, const meta_ctx &area)
         : any{meta_ctx_arg, area} {}
         : any{meta_ctx_arg, area} {}
 
 
-    /**
-     * @brief Creates a handle that points to an unmanaged object.
-     * @param value An instance of an object to use to initialize the handle.
-     */
-    meta_handle(meta_any &value)
-        : any{value.as_ref()} {}
-
-    /**
-     * @brief Creates a handle that points to an unmanaged object.
-     * @param value An instance of an object to use to initialize the handle.
-     */
-    meta_handle(const meta_any &value)
-        : any{value.as_ref()} {}
-
     /**
     /**
      * @brief Creates a handle that points to an unmanaged object.
      * @brief Creates a handle that points to an unmanaged object.
      * @tparam Type Type of object to use to initialize the handle.
      * @tparam Type Type of object to use to initialize the handle.
@@ -684,7 +679,7 @@ struct meta_handle {
      */
      */
     template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, meta_handle>>>
     template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, meta_handle>>>
     meta_handle(const meta_ctx &ctx, Type &value)
     meta_handle(const meta_ctx &ctx, Type &value)
-        : any{ctx, std::in_place_type<Type &>, value} {}
+        : meta_handle{0, ctx, value} {}
 
 
     /**
     /**
      * @brief Creates a handle that points to an unmanaged object.
      * @brief Creates a handle that points to an unmanaged object.
@@ -693,7 +688,7 @@ struct meta_handle {
      */
      */
     template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, meta_handle>>>
     template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, meta_handle>>>
     meta_handle(Type &value)
     meta_handle(Type &value)
-        : any{std::in_place_type<Type &>, value} {}
+        : meta_handle{0, locator<meta_ctx>::value_or(), value} {}
 
 
     /**
     /**
      * @brief Context aware copy constructor.
      * @brief Context aware copy constructor.