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

meta: extrapolate can_cast_or_convert

Michele Caini 4 лет назад
Родитель
Сommit
e857aa0640
2 измененных файлов с 23 добавлено и 22 удалено
  1. 2 22
      src/entt/meta/meta.hpp
  2. 21 0
      src/entt/meta/node.hpp

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

@@ -1033,30 +1033,10 @@ private:
 
 
 /*! @brief Opaque wrapper for types. */
 /*! @brief Opaque wrapper for types. */
 class meta_type {
 class meta_type {
-    [[nodiscard]] static bool can_cast_or_convert(const internal::meta_type_node *type, const meta_type other) ENTT_NOEXCEPT {
-        if(type->info == other.info()) {
-            return true;
-        }
-
-        for(const auto *curr = type->conv; curr; curr = curr->next) {
-            if(curr->type->info == other.info()) {
-                return true;
-            }
-        }
-
-        for(const auto *curr = type->base; curr; curr = curr->next) {
-            if(can_cast_or_convert(curr->type, other)) {
-                return true;
-            }
-        }
-
-        return (type->conversion_helper && other.node->conversion_helper);
-    }
-
     template<typename... Args, auto... Index>
     template<typename... Args, auto... Index>
     [[nodiscard]] static const internal::meta_ctor_node * ctor(const internal::meta_ctor_node *curr, std::index_sequence<Index...>) {
     [[nodiscard]] static const internal::meta_ctor_node * ctor(const internal::meta_ctor_node *curr, std::index_sequence<Index...>) {
         for(; curr; curr = curr->next) {
         for(; curr; curr = curr->next) {
-            if(curr->arity == sizeof...(Args) && (can_cast_or_convert(internal::meta_node<std::remove_const_t<std::remove_reference_t<Args>>>::resolve(), curr->arg(Index)) && ...)) {
+            if(curr->arity == sizeof...(Args) && (internal::can_cast_or_convert(internal::meta_node<std::remove_const_t<std::remove_reference_t<Args>>>::resolve(), curr->arg(Index).node) && ...)) {
                 return curr;
                 return curr;
             }
             }
         }
         }
@@ -1355,7 +1335,7 @@ public:
             for(size_type next{}; next < sz && next == (direct + ext); ++next) {
             for(size_type next{}; next < sz && next == (direct + ext); ++next) {
                 const auto type = args[next].type();
                 const auto type = args[next].type();
                 const auto other = it->arg(next);
                 const auto other = it->arg(next);
-                type.info() == other.info() ? ++direct : (ext += can_cast_or_convert(type.node, other));
+                type.info() == other.info() ? ++direct : (ext += internal::can_cast_or_convert(type.node, other.node));
             }
             }
 
 
             if((direct + ext) == sz) {
             if((direct + ext) == sz) {

+ 21 - 0
src/entt/meta/node.hpp

@@ -235,6 +235,27 @@ template<auto Member, typename Op>
 }
 }
 
 
 
 
+[[nodiscard]] inline bool can_cast_or_convert(const internal::meta_type_node *type, const internal::meta_type_node *other) ENTT_NOEXCEPT {
+    if(type->info == other->info) {
+        return true;
+    }
+
+    for(const auto *curr = type->conv; curr; curr = curr->next) {
+        if(curr->type->info == other->info) {
+            return true;
+        }
+    }
+
+    for(const auto *curr = type->base; curr; curr = curr->next) {
+        if(can_cast_or_convert(curr->type, other)) {
+            return true;
+        }
+    }
+
+    return (type->conversion_helper && other->conversion_helper);
+}
+
+
 }
 }