Procházet zdrojové kódy

meta: turn meta_any::operator!= into an in-class method (close #917)

Michele Caini před 3 roky
rodič
revize
6462ceb1f5
2 změnil soubory, kde provedl 8 přidání a 13 odebrání
  1. 6 11
      src/entt/meta/meta.hpp
  2. 2 2
      test/entt/meta/meta_any.cpp

+ 6 - 11
src/entt/meta/meta.hpp

@@ -525,10 +525,15 @@ public:
     }
     }
 
 
     /*! @copydoc any::operator== */
     /*! @copydoc any::operator== */
-    [[nodiscard]] bool operator==(const meta_any &other) const {
+    [[nodiscard]] bool operator==(const meta_any &other) const noexcept {
         return (!node && !other.node) || (node && other.node && *node->info == *other.node->info && storage == other.storage);
         return (!node && !other.node) || (node && other.node && *node->info == *other.node->info && storage == other.storage);
     }
     }
 
 
+    /*! @copydoc any::operator!= */
+    [[nodiscard]] bool operator!=(const meta_any &other) const noexcept {
+        return !(*this == other);
+    }
+
     /*! @copydoc any::as_ref */
     /*! @copydoc any::as_ref */
     [[nodiscard]] meta_any as_ref() noexcept {
     [[nodiscard]] meta_any as_ref() noexcept {
         return meta_any{*this, storage.as_ref()};
         return meta_any{*this, storage.as_ref()};
@@ -550,16 +555,6 @@ private:
     vtable_type *vtable;
     vtable_type *vtable;
 };
 };
 
 
-/**
- * @brief Checks if two wrappers differ in their content.
- * @param lhs A wrapper, either empty or not.
- * @param rhs A wrapper, either empty or not.
- * @return True if the two wrappers differ in their content, false otherwise.
- */
-[[nodiscard]] inline bool operator!=(const meta_any &lhs, const meta_any &rhs) noexcept {
-    return !(lhs == rhs);
-}
-
 /**
 /**
  * @brief Constructs a wrapper from a given type, passing it all arguments.
  * @brief Constructs a wrapper from a given type, passing it all arguments.
  * @tparam Type Type of object to use to initialize the wrapper.
  * @tparam Type Type of object to use to initialize the wrapper.

+ 2 - 2
test/entt/meta/meta_any.cpp

@@ -130,7 +130,7 @@ TEST_F(MetaAny, NoSBO) {
     ASSERT_EQ(any.cast<fat_t>(), instance);
     ASSERT_EQ(any.cast<fat_t>(), instance);
     ASSERT_NE(any.data(), nullptr);
     ASSERT_NE(any.data(), nullptr);
     ASSERT_EQ(any, entt::meta_any{instance});
     ASSERT_EQ(any, entt::meta_any{instance});
-    ASSERT_NE(fat_t{}, any);
+    ASSERT_NE(any, fat_t{});
 }
 }
 
 
 TEST_F(MetaAny, Empty) {
 TEST_F(MetaAny, Empty) {
@@ -572,7 +572,7 @@ TEST_F(MetaAny, NoSBODirectAssignment) {
     ASSERT_FALSE(any.try_cast<std::size_t>());
     ASSERT_FALSE(any.try_cast<std::size_t>());
     ASSERT_EQ(any.cast<fat_t>(), instance);
     ASSERT_EQ(any.cast<fat_t>(), instance);
     ASSERT_EQ(any, (entt::meta_any{fat_t{.1, .2, .3, .4}}));
     ASSERT_EQ(any, (entt::meta_any{fat_t{.1, .2, .3, .4}}));
-    ASSERT_NE(fat_t{}, any);
+    ASSERT_NE(any, fat_t{});
 }
 }
 
 
 TEST_F(MetaAny, NoSBOAssignValue) {
 TEST_F(MetaAny, NoSBOAssignValue) {