Procházet zdrojové kódy

meta: operator==/!= for meta_handle (see #1002)

Michele Caini před 3 roky
rodič
revize
fc58ff74be
2 změnil soubory, kde provedl 20 přidání a 0 odebrání
  1. 10 0
      src/entt/meta/meta.hpp
  2. 10 0
      test/entt/meta/meta_handle.cpp

+ 10 - 0
src/entt/meta/meta.hpp

@@ -722,6 +722,16 @@ struct meta_handle {
         return static_cast<bool>(any);
         return static_cast<bool>(any);
     }
     }
 
 
+    /*! @copydoc meta_any::operator== */
+    [[nodiscard]] bool operator==(const meta_handle &other) const noexcept {
+        return (any == other.any);
+    }
+
+    /*! @copydoc meta_any::operator!= */
+    [[nodiscard]] bool operator!=(const meta_handle &other) const noexcept {
+        return !(*this == other);
+    }
+
     /**
     /**
      * @brief Access operator for accessing the contained opaque object.
      * @brief Access operator for accessing the contained opaque object.
      * @return A wrapper that shares a reference to an unmanaged object.
      * @return A wrapper that shares a reference to an unmanaged object.

+ 10 - 0
test/entt/meta/meta_handle.cpp

@@ -44,12 +44,22 @@ TEST_F(MetaHandle, Functionalities) {
     ASSERT_FALSE(handle);
     ASSERT_FALSE(handle);
     ASSERT_FALSE(chandle);
     ASSERT_FALSE(chandle);
 
 
+    ASSERT_EQ(handle, chandle);
+    ASSERT_EQ(handle, entt::meta_handle{});
+    ASSERT_FALSE(handle != handle);
+    ASSERT_TRUE(handle == handle);
+
     handle = entt::meta_handle{instance};
     handle = entt::meta_handle{instance};
     chandle = entt::meta_handle{std::as_const(instance)};
     chandle = entt::meta_handle{std::as_const(instance)};
 
 
     ASSERT_TRUE(handle);
     ASSERT_TRUE(handle);
     ASSERT_TRUE(chandle);
     ASSERT_TRUE(chandle);
 
 
+    ASSERT_EQ(handle, chandle);
+    ASSERT_NE(handle, entt::meta_handle{});
+    ASSERT_FALSE(handle != handle);
+    ASSERT_TRUE(handle == handle);
+
     ASSERT_TRUE(handle->invoke("incr"_hs));
     ASSERT_TRUE(handle->invoke("incr"_hs));
     ASSERT_FALSE(chandle->invoke("incr"_hs));
     ASSERT_FALSE(chandle->invoke("incr"_hs));
     ASSERT_FALSE(std::as_const(handle)->invoke("incr"_hs));
     ASSERT_FALSE(std::as_const(handle)->invoke("incr"_hs));