Browse Source

meta: operator==/!= for meta_prop

Michele Caini 3 years ago
parent
commit
3a4672793d
2 changed files with 24 additions and 0 deletions
  1. 19 0
      src/entt/meta/meta.hpp
  2. 5 0
      test/entt/meta/meta_prop.cpp

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

@@ -789,11 +789,30 @@ struct meta_prop {
         return (node != nullptr);
     }
 
+    /**
+     * @brief Checks if two objects refer to the same type.
+     * @param other The object with which to compare.
+     * @return True if the objects refer to the same type, false otherwise.
+     */
+    [[nodiscard]] bool operator==(const meta_prop &other) const noexcept {
+        return (ctx == other.ctx && node == other.node);
+    }
+
 private:
     const internal::meta_prop_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_prop &lhs, const meta_prop &rhs) noexcept {
+    return !(lhs == rhs);
+}
+
 /*! @brief Opaque wrapper for data members. */
 struct meta_data {
     /*! @brief Unsigned integer type. */

+ 5 - 0
test/entt/meta/meta_prop.cpp

@@ -50,6 +50,11 @@ TEST_F(MetaProp, Functionalities) {
 
     ASSERT_TRUE(prop);
 
+    ASSERT_EQ(prop, prop);
+    ASSERT_NE(prop, entt::meta_prop{});
+    ASSERT_FALSE(prop != prop);
+    ASSERT_TRUE(prop == prop);
+
     auto value = prop.value();
     auto cvalue = std::as_const(prop).value();