diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index c53a40cee..0e7aaaf9a 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -421,8 +421,11 @@ public: */ template [[nodiscard]] meta_any allow_cast() const { - const auto other = allow_cast(internal::meta_node>>::resolve()); - return (!std::is_reference_v || std::is_const_v> || other.owner()) ? other : meta_any{}; + if constexpr(std::is_reference_v && !std::is_const_v>) { + return meta_any{}; + } else { + return allow_cast(internal::meta_node>>::resolve()); + } } /** @@ -432,16 +435,11 @@ public: */ template bool allow_cast() { - if(auto other = std::as_const(*this).allow_cast(internal::meta_node>>::resolve()); other) { - if(other.owner()) { - std::swap(*this, other); - return true; - } - - return (static_cast> &>(storage).data() != nullptr); + if constexpr(std::is_reference_v && !std::is_const_v>) { + return allow_cast(internal::meta_node>>::resolve()) && (storage.data() != nullptr); + } else { + return allow_cast(internal::meta_node>>::resolve()); } - - return false; } /*! @copydoc any::emplace */