meta: operator==/!= for meta_data (close #1002)

This commit is contained in:
Michele Caini
2023-04-06 12:39:50 +02:00
parent fc58ff74be
commit 0a0446f35c
2 changed files with 21 additions and 0 deletions
+15
View File
@@ -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. */
+6
View File
@@ -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<int>());
ASSERT_EQ(data.arg(0u), entt::resolve<int>());