From fc58ff74bedf0c2b052846311e6074bd2d5a5ef6 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 6 Apr 2023 12:39:19 +0200 Subject: [PATCH] meta: operator==/!= for meta_handle (see #1002) --- src/entt/meta/meta.hpp | 10 ++++++++++ test/entt/meta/meta_handle.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index c78249208..a3584a736 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -722,6 +722,16 @@ struct meta_handle { return static_cast(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. diff --git a/test/entt/meta/meta_handle.cpp b/test/entt/meta/meta_handle.cpp index d5786d5e1..a4ba54514 100644 --- a/test/entt/meta/meta_handle.cpp +++ b/test/entt/meta/meta_handle.cpp @@ -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));