diff --git a/src/entt/core/any.hpp b/src/entt/core/any.hpp index bff05ef4f..6822eb231 100644 --- a/src/entt/core/any.hpp +++ b/src/entt/core/any.hpp @@ -374,7 +374,7 @@ Type any_cast(basic_any &data) ENTT_NOEXCEPT { /*! @copydoc any_cast */ template Type any_cast(basic_any &&data) ENTT_NOEXCEPT { - if constexpr(std::is_copy_constructible_v>) { + if constexpr(std::is_copy_constructible_v>>) { if(auto * const instance = any_cast>(&data); instance) { return static_cast(std::move(*instance)); } else { @@ -391,15 +391,23 @@ Type any_cast(basic_any &&data) ENTT_NOEXCEPT { /*! @copydoc any_cast */ template const Type * any_cast(const basic_any *data) ENTT_NOEXCEPT { - return (data->type() == type_id() ? static_cast(data->data()) : nullptr); + if(const auto hash = type_hash>>::value(); hash == data->type().hash_code()) { + return static_cast(data->data()); + } + + return nullptr; } /*! @copydoc any_cast */ template Type * any_cast(basic_any *data) ENTT_NOEXCEPT { - // last attempt to make wrappers for const references return their values - return (data->type() == type_id() ? static_cast(static_cast, Type> *>(data)->data()) : nullptr); + if(const auto hash = type_hash>>::value(); hash == data->type().hash_code()) { + // last attempt to make wrappers for const references return their values + return static_cast(static_cast, Type> *>(data)->data()); + } + + return nullptr; }