type_info: a better operator==

This commit is contained in:
Michele Caini
2020-10-13 13:48:18 +02:00
parent b7711f0182
commit a3e03fb889
2 changed files with 11 additions and 7 deletions

View File

@@ -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:

View File

@@ -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);