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

meta: operator==/!= for meta_func

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

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

@@ -1053,11 +1053,26 @@ struct meta_func {
         return (node != nullptr);
     }
 
+    /*! @copydoc meta_prop::operator== */
+    [[nodiscard]] bool operator==(const meta_func &other) const noexcept {
+        return (ctx == other.ctx && node == other.node);
+    }
+
 private:
     const internal::meta_func_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_func &lhs, const meta_func &rhs) noexcept {
+    return !(lhs == rhs);
+}
+
 /*! @brief Opaque wrapper for types. */
 class meta_type {
     template<typename Func>

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

@@ -170,6 +170,12 @@ TEST_F(MetaFunc, Functionalities) {
     func_t instance{};
 
     ASSERT_TRUE(func);
+
+    ASSERT_EQ(func, func);
+    ASSERT_NE(func, entt::meta_func{});
+    ASSERT_FALSE(func != func);
+    ASSERT_TRUE(func == func);
+
     ASSERT_EQ(func.arity(), 2u);
     ASSERT_FALSE(func.is_const());
     ASSERT_FALSE(func.is_static());