Browse Source

updated entt::null comparison functions

Michele Caini 6 years ago
parent
commit
eec1937f52
2 changed files with 9 additions and 4 deletions
  1. 8 4
      src/entt/entity/entity.hpp
  2. 1 0
      test/entt/entity/entity.cpp

+ 8 - 4
src/entt/entity/entity.hpp

@@ -107,10 +107,14 @@ struct entt_traits<std::uint64_t> {
 namespace internal {
 
 
-struct null {
+class null {
+    template<typename Entity>
+    using traits_type = entt_traits<std::underlying_type_t<Entity>>;
+
+public:
     template<typename Entity>
     constexpr operator Entity() const ENTT_NOEXCEPT {
-        return Entity{entt_traits<std::underlying_type_t<Entity>>::entity_mask};
+        return Entity{traits_type<Entity>::entity_mask};
     }
 
     constexpr bool operator==(null) const ENTT_NOEXCEPT {
@@ -123,12 +127,12 @@ struct null {
 
     template<typename Entity>
     constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
-        return entity == static_cast<Entity>(*this);
+        return (to_integer(entity) & traits_type<Entity>::entity_mask) == to_integer(static_cast<Entity>(*this));
     }
 
     template<typename Entity>
     constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
-        return entity != static_cast<Entity>(*this);
+        return !(entity == *this);
     }
 };
 

+ 1 - 0
test/entt/entity/entity.cpp

@@ -13,6 +13,7 @@ TEST(Traits, Null) {
     registry.assign<int>(entity, 42);
 
     ASSERT_TRUE(entt::entity{traits_type::entity_mask} == entt::null);
+    ASSERT_TRUE(entt::entity{~typename traits_type::entity_type{}} == entt::null);
 
     ASSERT_TRUE(entt::null == entt::null);
     ASSERT_FALSE(entt::null != entt::null);