diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index a3584a736..2ea7d4001 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -894,11 +894,26 @@ struct meta_data { return (node != nullptr); } + /*! @copydoc meta_prop::operator== */ + [[nodiscard]] bool operator==(const meta_data &other) const noexcept { + return (ctx == other.ctx && node == other.node); + } + private: const internal::meta_data_node *node; const meta_ctx *ctx; }; +/** + * @brief Checks if two objects refer to the same type. + * @param lhs An object, either valid or not. + * @param rhs An object, either valid or not. + * @return False if the objects refer to the same node, true otherwise. + */ +[[nodiscard]] inline bool operator!=(const meta_data &lhs, const meta_data &rhs) noexcept { + return !(lhs == rhs); +} + /*! @brief Opaque wrapper for member functions. */ struct meta_func { /*! @brief Unsigned integer type. */ diff --git a/test/entt/meta/meta_data.cpp b/test/entt/meta/meta_data.cpp index 58b9b084a..36b782376 100644 --- a/test/entt/meta/meta_data.cpp +++ b/test/entt/meta/meta_data.cpp @@ -164,6 +164,12 @@ TEST_F(MetaData, Functionalities) { clazz_t instance{}; ASSERT_TRUE(data); + + ASSERT_EQ(data, data); + ASSERT_NE(data, entt::meta_data{}); + ASSERT_FALSE(data != data); + ASSERT_TRUE(data == data); + ASSERT_EQ(data.arity(), 1u); ASSERT_EQ(data.type(), entt::resolve()); ASSERT_EQ(data.arg(0u), entt::resolve());