From 76b380d7c0dfbdf51e1a99d1bdb60fcd494de98d Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 4 Aug 2022 15:09:27 +0200 Subject: [PATCH] meta: review meta_any::allow_cast --- src/entt/meta/meta.hpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) 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 */