From e857aa0640e936eecb1a1cd16f22f2d5463a4626 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 13 Sep 2021 11:54:40 +0200 Subject: [PATCH] meta: extrapolate can_cast_or_convert --- src/entt/meta/meta.hpp | 24 ++---------------------- src/entt/meta/node.hpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 7ff979876..df47a3671 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -1033,30 +1033,10 @@ private: /*! @brief Opaque wrapper for types. */ 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 [[nodiscard]] static const internal::meta_ctor_node * ctor(const internal::meta_ctor_node *curr, std::index_sequence) { for(; curr; curr = curr->next) { - if(curr->arity == sizeof...(Args) && (can_cast_or_convert(internal::meta_node>>::resolve(), curr->arg(Index)) && ...)) { + if(curr->arity == sizeof...(Args) && (internal::can_cast_or_convert(internal::meta_node>>::resolve(), curr->arg(Index).node) && ...)) { return curr; } } @@ -1355,7 +1335,7 @@ public: for(size_type next{}; next < sz && next == (direct + ext); ++next) { const auto type = args[next].type(); 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) { diff --git a/src/entt/meta/node.hpp b/src/entt/meta/node.hpp index 0e41095fd..d2c745ab7 100644 --- a/src/entt/meta/node.hpp +++ b/src/entt/meta/node.hpp @@ -235,6 +235,27 @@ template } +[[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); +} + + }