Просмотр исходного кода

meta: shared meta_object<Type>::traits()

skypjack 1 день назад
Родитель
Сommit
ed95aab1d5
1 измененных файлов с 11 добавлено и 22 удалено
  1. 11 22
      src/entt/meta/meta.hpp

+ 11 - 22
src/entt/meta/meta.hpp

@@ -848,6 +848,17 @@ public:
         return node_or_assert().custom;
     }
 
+    /**
+     * @brief Returns all meta traits for a given meta object.
+     * @tparam Type The type to convert the meta traits to.
+     * @return The registered meta traits, if any.
+     */
+    template<typename Type>
+    [[nodiscard]] Type traits() const noexcept
+    requires requires(node_type elem) { elem.traits; } {
+        return internal::meta_to_user_traits<Type>(node_or_assert().traits);
+    }
+
     /*! @copydoc meta_any::context */
     [[nodiscard]] const meta_ctx &context() const noexcept {
         return *ctx;
@@ -936,16 +947,6 @@ struct meta_data final: meta_object<internal::meta_data_node> {
      * @return The type of the i-th argument of a data member's getter.
      */
     [[nodiscard]] inline meta_type get_arg(size_type index) const noexcept;
-
-    /**
-     * @brief Returns all meta traits for a given meta object.
-     * @tparam Type The type to convert the meta traits to.
-     * @return The registered meta traits, if any.
-     */
-    template<typename Type>
-    [[nodiscard]] Type traits() const noexcept {
-        return internal::meta_to_user_traits<Type>(node_or_assert().traits);
-    }
 };
 
 /*! @brief Opaque wrapper for member functions. */
@@ -1002,12 +1003,6 @@ struct meta_func final: meta_object<internal::meta_func_node> {
         return (sizeof...(args) == arity()) ? node_or_assert().invoke(meta_handle{context(), stl::forward<Instance>(instance)}, stl::array<meta_any, sizeof...(args)>{meta_any{context(), stl::forward<decltype(args)>(args)}...}.data()) : meta_any{meta_ctx_arg, context()};
     }
 
-    /*! @copydoc meta_data::traits */
-    template<typename Type>
-    [[nodiscard]] Type traits() const noexcept {
-        return internal::meta_to_user_traits<Type>(node_or_assert().traits);
-    }
-
     /**
      * @brief Returns the next overload of a given function, if any.
      * @return The next overload of the given function, if any.
@@ -1407,12 +1402,6 @@ public:
         const auto candidate = data(id);
         return candidate ? candidate.get(stl::forward<Instance>(instance), stl::forward<decltype(args)>(args)...) : meta_any{meta_ctx_arg, context()};
     }
-
-    /*! @copydoc meta_data::traits */
-    template<typename Type>
-    [[nodiscard]] Type traits() const noexcept {
-        return internal::meta_to_user_traits<Type>(node_or_assert().traits);
-    }
 };
 
 [[nodiscard]] inline meta_type meta_any::type() const noexcept {