1
0
Эх сурвалжийг харах

type_info: a better operator==

Michele Caini 5 жил өмнө
parent
commit
a3e03fb889

+ 1 - 1
src/entt/core/type_info.hpp

@@ -201,7 +201,7 @@ public:
      * @return False if the two contents differ, true otherwise.
      */
     [[nodiscard]] bool operator==(const type_info &other) const ENTT_NOEXCEPT {
-        return hash_func == other.hash_func;
+        return (!hash_func && !other.hash_func) || (hash_func && other.hash_func && hash_func() == other.hash_func());
     }
 
 private:

+ 10 - 6
test/entt/core/type_info.cpp

@@ -30,16 +30,20 @@ TEST(TypeName, Functionalities) {
 }
 
 TEST(TypeInfo, Functionalities) {
+    static_assert(std::is_default_constructible_v<entt::type_info>);
+    static_assert(std::is_copy_constructible_v<entt::type_info>);
+    static_assert(std::is_move_constructible_v<entt::type_info>);
+    static_assert(std::is_copy_assignable_v<entt::type_info>);
+    static_assert(std::is_move_assignable_v<entt::type_info>);
+
+    ASSERT_EQ(entt::type_info{}, entt::type_info{});
+    ASSERT_NE(entt::type_id<int>(), entt::type_info{});
+    ASSERT_NE(entt::type_id<int>(), entt::type_id<char>());
+
     auto info = entt::type_id<int>();
     auto other = entt::type_id(42);
     entt::type_info empty{};
 
-    static_assert(std::is_default_constructible_v<decltype(info)>);
-    static_assert(std::is_copy_constructible_v<decltype(info)>);
-    static_assert(std::is_move_constructible_v<decltype(info)>);
-    static_assert(std::is_copy_assignable_v<decltype(info)>);
-    static_assert(std::is_move_assignable_v<decltype(info)>);
-
     ASSERT_EQ(info, other);
     ASSERT_NE(info, empty);