Просмотр исходного кода

any: turn operator!= into an in-class method

Michele Caini 3 лет назад
Родитель
Сommit
e2f8ea110a
1 измененных файлов с 10 добавлено и 14 удалено
  1. 10 14
      src/entt/core/any.hpp

+ 10 - 14
src/entt/core/any.hpp

@@ -368,7 +368,7 @@ public:
      * @param other Wrapper with which to compare.
      * @return False if the two objects differ in their content, true otherwise.
      */
-    bool operator==(const basic_any &other) const noexcept {
+    [[nodiscard]] bool operator==(const basic_any &other) const noexcept {
         if(vtable && *info == *other.info) {
             return (vtable(operation::compare, *this, other.data()) != nullptr);
         }
@@ -376,6 +376,15 @@ public:
         return (!vtable && !other.vtable);
     }
 
+    /**
+     * @brief Checks if two wrappers differ in their content.
+     * @param other Wrapper with which to compare.
+     * @return True if the two objects differ in their content, false otherwise.
+     */
+    [[nodiscard]] bool operator!=(const basic_any &other) const noexcept {
+        return !(*this == other);
+    }
+
     /**
      * @brief Aliasing constructor.
      * @return A wrapper that shares a reference to an unmanaged object.
@@ -407,19 +416,6 @@ private:
     policy mode;
 };
 
-/**
- * @brief Checks if two wrappers differ in their content.
- * @tparam Len Size of the storage reserved for the small buffer optimization.
- * @tparam Align Alignment requirement.
- * @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.
- */
-template<std::size_t Len, std::size_t Align>
-[[nodiscard]] inline bool operator!=(const basic_any<Len, Align> &lhs, const basic_any<Len, Align> &rhs) noexcept {
-    return !(lhs == rhs);
-}
-
 /**
  * @brief Performs type-safe access to the contained object.
  * @tparam Type Type to which conversion is required.