Преглед изворни кода

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

Michele Caini пре 3 година
родитељ
комит
0a0446f35c
2 измењених фајлова са 21 додато и 0 уклоњено
  1. 15 0
      src/entt/meta/meta.hpp
  2. 6 0
      test/entt/meta/meta_data.cpp

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

@@ -894,11 +894,26 @@ struct meta_data {
         return (node != nullptr);
         return (node != nullptr);
     }
     }
 
 
+    /*! @copydoc meta_prop::operator== */
+    [[nodiscard]] bool operator==(const meta_data &other) const noexcept {
+        return (ctx == other.ctx && node == other.node);
+    }
+
 private:
 private:
     const internal::meta_data_node *node;
     const internal::meta_data_node *node;
     const meta_ctx *ctx;
     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. */
 /*! @brief Opaque wrapper for member functions. */
 struct meta_func {
 struct meta_func {
     /*! @brief Unsigned integer type. */
     /*! @brief Unsigned integer type. */

+ 6 - 0
test/entt/meta/meta_data.cpp

@@ -164,6 +164,12 @@ TEST_F(MetaData, Functionalities) {
     clazz_t instance{};
     clazz_t instance{};
 
 
     ASSERT_TRUE(data);
     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.arity(), 1u);
     ASSERT_EQ(data.type(), entt::resolve<int>());
     ASSERT_EQ(data.type(), entt::resolve<int>());
     ASSERT_EQ(data.arg(0u), entt::resolve<int>());
     ASSERT_EQ(data.arg(0u), entt::resolve<int>());