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

*: operator== is not defined as member if unnecessary

Michele Caini 4 лет назад
Родитель
Сommit
89aa2a1902
3 измененных файлов с 42 добавлено и 35 удалено
  1. 13 9
      src/entt/core/hashed_string.hpp
  2. 12 10
      src/entt/core/type_info.hpp
  3. 17 16
      src/entt/entity/handle.hpp

+ 13 - 9
src/entt/core/hashed_string.hpp

@@ -186,15 +186,6 @@ public:
      */
     [[nodiscard]] constexpr operator hash_type() const ENTT_NOEXCEPT { return value(); }
 
-    /**
-     * @brief Compares two hashed strings.
-     * @param other Hashed string with which to compare.
-     * @return True if the two hashed strings are identical, false otherwise.
-     */
-    [[nodiscard]] constexpr bool operator==(const basic_hashed_string &other) const ENTT_NOEXCEPT {
-        return hash == other.hash;
-    }
-
 private:
     const value_type *str;
     hash_type hash;
@@ -224,6 +215,19 @@ basic_hashed_string(const Char (&str)[N])
  * @return True if the two hashed strings are identical, false otherwise.
  */
 template<typename Char>
+[[nodiscard]] constexpr bool operator==(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
+    return lhs.value() == rhs.value();
+}
+
+
+/**
+ * @brief Compares two hashed strings.
+ * @tparam Char Character type.
+ * @param lhs A valid hashed string.
+ * @param rhs A valid hashed string.
+ * @return True if the two hashed strings differ, false otherwise.
+ */
+template<typename Char>
 [[nodiscard]] constexpr bool operator!=(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
     return !(lhs == rhs);
 }

+ 12 - 10
src/entt/core/type_info.hpp

@@ -216,15 +216,6 @@ struct type_info final {
         return alias;
     }
 
-    /**
-     * @brief Compares the contents of two type info objects.
-     * @param other Object with which to compare.
-     * @return False if the two contents differ, true otherwise.
-     */
-    [[nodiscard]] constexpr bool operator==(const type_info &other) const ENTT_NOEXCEPT {
-        return identifier == other.identifier;
-    }
-
 private:
     id_type seq;
     id_type identifier;
@@ -236,7 +227,18 @@ private:
  * @brief Compares the contents of two type info objects.
  * @param lhs A type info object.
  * @param rhs A type info object.
- * @return True if the two contents differ, false otherwise.
+ * @return True if the two type info objects are identical, false otherwise.
+ */
+[[nodiscard]] inline constexpr bool operator==(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
+    return lhs.hash() == rhs.hash();
+}
+
+
+/**
+ * @brief Compares the contents of two type info objects.
+ * @param lhs A type info object.
+ * @param rhs A type info object.
+ * @return True if the two type info objects differ, false otherwise.
  */
 [[nodiscard]] inline constexpr bool operator!=(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
     return !(lhs == rhs);

+ 17 - 16
src/entt/entity/handle.hpp

@@ -47,18 +47,6 @@ struct basic_handle {
         : reg{&ref}, entt{value}
     {}
 
-    /**
-     * @brief Compares two handles.
-     * @tparam Args Template parameters of the handle with which to compare.
-     * @param other Handle with which to compare.
-     * @return True if both handles refer to the same registry and the same
-     * entity, false otherwise.
-     */
-    template<typename... Args>
-    [[nodiscard]] bool operator==(const basic_handle<Args...> &other) const ENTT_NOEXCEPT {
-        return reg == other.registry() && entt == other.entity();
-    }
-
     /**
      * @brief Constructs a const handle from a non-const one.
      * @tparam Other A valid entity type (see entt_traits for more details).
@@ -301,15 +289,28 @@ private:
 
 /**
  * @brief Compares two handles.
- * @tparam Type A valid entity type (see entt_traits for more details).
- * @tparam Other A valid entity type (see entt_traits for more details).
+ * @tparam Args Template parameters of the handles to compare.
+ * @param lhs A valid handle.
+ * @param rhs A valid handle.
+ * @return True if both handles refer to the same registry and the same
+ * entity, false otherwise.
+ */
+template<typename... Args>
+[[nodiscard]] bool operator==(const basic_handle<Args...> &lhs, const basic_handle<Args...> &rhs) ENTT_NOEXCEPT {
+    return lhs.registry() == rhs.registry() && lhs.entity() == rhs.entity();
+}
+
+
+/**
+ * @brief Compares two handles.
+ * @tparam Args Template parameters of the handles to compare.
  * @param lhs A valid handle.
  * @param rhs A valid handle.
  * @return False if both handles refer to the same registry and the same
  * entity, true otherwise.
  */
-template<typename Type, typename Other>
-bool operator!=(const basic_handle<Type> &lhs, const basic_handle<Other> &rhs) ENTT_NOEXCEPT {
+template<typename... Args>
+[[nodiscard]] bool operator!=(const basic_handle<Args...> &lhs, const basic_handle<Args...> &rhs) ENTT_NOEXCEPT {
     return !(lhs == rhs);
 }