From df10c0fcdce7bf03b1cb0c9410a4ade6a3fa5099 Mon Sep 17 00:00:00 2001 From: skypjack Date: Mon, 12 Jan 2026 12:59:02 +0100 Subject: [PATCH] type_info: operator==/operator<=> --- src/entt/core/type_info.hpp | 72 ++++++++++--------------------------- 1 file changed, 19 insertions(+), 53 deletions(-) diff --git a/src/entt/core/type_info.hpp b/src/entt/core/type_info.hpp index a2cc14e82..c736ef388 100644 --- a/src/entt/core/type_info.hpp +++ b/src/entt/core/type_info.hpp @@ -1,6 +1,7 @@ #ifndef ENTT_CORE_TYPE_INFO_HPP #define ENTT_CORE_TYPE_INFO_HPP +#include #include #include #include @@ -175,65 +176,30 @@ struct type_info final { return alias; } + /** + * @brief Compares two type info objects. + * @param other A type info object. + * @return True if the two type info objects are identical, false otherwise. + */ + [[nodiscard]] constexpr bool operator==(const type_info &other) const noexcept { + return identifier == other.identifier; + } + + /** + * @brief Lexicographically compares two type info objects. + * @param other A type info object. + * @return The relative order between the two type info objects. + */ + [[nodiscard]] constexpr auto operator<=>(const type_info &other) const noexcept { + return seq <=> other.seq; + } + private: id_type seq; id_type identifier; std::string_view alias; }; -/** - * @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 are identical, false otherwise. - */ -[[nodiscard]] constexpr bool operator==(const type_info &lhs, const type_info &rhs) noexcept { - return lhs.hash() == rhs.hash(); -} - -/** - * @brief Compares two type info objects. - * @param lhs A valid type info object. - * @param rhs A valid type info object. - * @return True if the first element is less than the second, false otherwise. - */ -[[nodiscard]] constexpr bool operator<(const type_info &lhs, const type_info &rhs) noexcept { - return lhs.index() < rhs.index(); -} - -/** - * @brief Compares two type info objects. - * @param lhs A valid type info object. - * @param rhs A valid type info object. - * @return True if the first element is less than or equal to the second, false - * otherwise. - */ -[[nodiscard]] constexpr bool operator<=(const type_info &lhs, const type_info &rhs) noexcept { - return !(rhs < lhs); -} - -/** - * @brief Compares two type info objects. - * @param lhs A valid type info object. - * @param rhs A valid type info object. - * @return True if the first element is greater than the second, false - * otherwise. - */ -[[nodiscard]] constexpr bool operator>(const type_info &lhs, const type_info &rhs) noexcept { - return rhs < lhs; -} - -/** - * @brief Compares two type info objects. - * @param lhs A valid type info object. - * @param rhs A valid type info object. - * @return True if the first element is greater than or equal to the second, - * false otherwise. - */ -[[nodiscard]] constexpr bool operator>=(const type_info &lhs, const type_info &rhs) noexcept { - return !(lhs < rhs); -} - /** * @brief Returns the type info object associated to a given type. *