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

This commit is contained in:
Michele Caini
2023-04-06 12:39:19 +02:00
parent fed6831cdc
commit fc58ff74be
2 changed files with 20 additions and 0 deletions

View File

@@ -722,6 +722,16 @@ struct meta_handle {
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.
* @return A wrapper that shares a reference to an unmanaged object.

View File

@@ -44,12 +44,22 @@ TEST_F(MetaHandle, Functionalities) {
ASSERT_FALSE(handle);
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};
chandle = entt::meta_handle{std::as_const(instance)};
ASSERT_TRUE(handle);
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_FALSE(chandle->invoke("incr"_hs));
ASSERT_FALSE(std::as_const(handle)->invoke("incr"_hs));