From 71f55e7ab1b842e7a6b41dbb72c086848fb379b3 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 9 Dec 2024 17:06:06 +0100 Subject: [PATCH] any: internal changes --- src/entt/core/any.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/entt/core/any.hpp b/src/entt/core/any.hpp index 29fe81b63..088ac50be 100644 --- a/src/entt/core/any.hpp +++ b/src/entt/core/any.hpp @@ -287,7 +287,7 @@ public: * @return The object type if any, `type_id()` otherwise. */ [[nodiscard]] const type_info &type() const noexcept { - return *info; + return (info == nullptr) ? type_id() : *info; } /** @@ -304,7 +304,7 @@ public: * @return An opaque pointer the contained instance, if any. */ [[nodiscard]] const void *data(const type_info &req) const noexcept { - return *info == req ? data() : nullptr; + return (type() == req) ? data() : nullptr; } /** @@ -342,7 +342,7 @@ public: * @return True in case of success, false otherwise. */ bool assign(const basic_any &other) { - if(vtable && mode != any_policy::cref && *info == *other.info) { + if(vtable && mode != any_policy::cref && *info == other.type()) { return (vtable(request::assign, *this, other.data()) != nullptr); } @@ -351,7 +351,7 @@ public: /*! @copydoc assign */ bool assign(basic_any &&other) { - if(vtable && mode != any_policy::cref && *info == *other.info) { + if(vtable && mode != any_policy::cref && *info == other.type()) { if(auto *val = other.data(); val) { return (vtable(request::transfer, *this, val) != nullptr); } @@ -369,7 +369,7 @@ public: } instance = nullptr; - info = &type_id(); + info = nullptr; vtable = nullptr; mode = any_policy::empty; } @@ -388,7 +388,7 @@ public: * @return False if the two objects differ in their content, true otherwise. */ [[nodiscard]] bool operator==(const basic_any &other) const noexcept { - if(vtable && *info == *other.info) { + if(vtable && *info == other.type()) { return (vtable(request::compare, *this, other.data()) != nullptr); } @@ -438,7 +438,7 @@ private: const void *instance; storage_type storage; }; - const type_info *info{&type_id()}; + const type_info *info{}; vtable_type *vtable{}; any_policy mode{any_policy::empty}; };