diff --git a/src/entt/entity/handle.hpp b/src/entt/entity/handle.hpp index 56f752890..5fc4487df 100644 --- a/src/entt/entity/handle.hpp +++ b/src/entt/entity/handle.hpp @@ -64,8 +64,10 @@ public: return operator*(); } - template - friend constexpr bool operator==(const handle_storage_iterator &, const handle_storage_iterator &) noexcept; + template + [[nodiscard]] constexpr bool operator==(const handle_storage_iterator &other) const noexcept { + return it == other.it; + } private: entity_type entt; @@ -73,11 +75,6 @@ private: It last; }; -template -[[nodiscard]] constexpr bool operator==(const handle_storage_iterator &lhs, const handle_storage_iterator &rhs) noexcept { - return lhs.it == rhs.it; -} - } // namespace internal /*! @endcond */ @@ -102,9 +99,9 @@ public: /*! @brief Type of registry accepted by the handle. */ using registry_type = Registry; /*! @brief Underlying entity identifier. */ - using entity_type = typename Registry::entity_type; + using entity_type = traits_type::value_type; /*! @brief Underlying version type. */ - using version_type = typename Registry::version_type; + using version_type = traits_type::version_type; /*! @brief Unsigned integer type. */ using size_type = std::size_t; /*! @brief Iterable handle type. */ @@ -326,6 +323,27 @@ public: return owner_or_assert().orphan(entt); } + /** + * @brief Compares two handles. + * @tparam Other Scope of the other handle. + * @param other A valid handle. + * @return True if both handles refer to the same registry and the same + * entity, false otherwise. + */ + template + [[nodiscard]] bool operator==(const basic_handle &other) const noexcept { + return owner == other.registry() && entt == other.entity(); + } + + /** + * @brief Compares a handle with the null object. + * @param other A null object yet to be converted. + * @return False if the two elements differ, true otherwise. + */ + [[nodiscard]] constexpr bool operator==(const null_t other) const noexcept { + return (entt == other); + } + /** * @brief Returns a const handle from a non-const one. * @tparam Other A valid entity type. @@ -345,68 +363,6 @@ private: entity_type entt; }; -/** - * @brief Compares two handles. - * @tparam Args Scope of the first handle. - * @tparam Other Scope of the second handle. - * @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 -[[nodiscard]] bool operator==(const basic_handle &lhs, const basic_handle &rhs) noexcept { - return lhs.registry() == rhs.registry() && lhs.entity() == rhs.entity(); -} - -/** - * @brief Compares a handle with the null object. - * @tparam Args Scope of the handle. - * @param lhs A valid handle. - * @param rhs A null object yet to be converted. - * @return False if the two elements differ, true otherwise. - */ -template -[[nodiscard]] constexpr bool operator==(const basic_handle &lhs, const null_t rhs) noexcept { - return (lhs.entity() == rhs); -} - -/** - * @brief Compares a handle with the null object. - * @tparam Args Scope of the handle. - * @param lhs A null object yet to be converted. - * @param rhs A valid handle. - * @return False if the two elements differ, true otherwise. - */ -template -[[nodiscard]] constexpr bool operator==(const null_t lhs, const basic_handle &rhs) noexcept { - return (rhs == lhs); -} - -/** - * @brief Compares a handle with the null object. - * @tparam Args Scope of the handle. - * @param lhs A valid handle. - * @param rhs A null object yet to be converted. - * @return True if the two elements differ, false otherwise. - */ -template -[[nodiscard]] constexpr bool operator!=(const basic_handle &lhs, const null_t rhs) noexcept { - return (lhs.entity() != rhs); -} - -/** - * @brief Compares a handle with the null object. - * @tparam Args Scope of the handle. - * @param lhs A null object yet to be converted. - * @param rhs A valid handle. - * @return True if the two elements differ, false otherwise. - */ -template -[[nodiscard]] constexpr bool operator!=(const null_t lhs, const basic_handle &rhs) noexcept { - return (rhs != lhs); -} - } // namespace entt #endif