diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index 77168c0bf..2fa5dbde2 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -1,6 +1,7 @@ #ifndef ENTT_ENTITY_SPARSE_SET_HPP #define ENTT_ENTITY_SPARSE_SET_HPP +#include #include #include #include @@ -84,6 +85,20 @@ struct sparse_set_iterator final { return operator[](0); } + [[nodiscard]] constexpr std::ptrdiff_t operator-(const sparse_set_iterator &other) const noexcept { + // intentionally reversed due to backward iteration + return other.offset - offset; + } + + [[nodiscard]] constexpr bool operator==(const sparse_set_iterator &other) const noexcept { + return offset == other.offset; + } + + [[nodiscard]] constexpr auto operator<=>(const sparse_set_iterator &other) const noexcept { + // intentionally reversed due to backward iteration + return other.offset <=> offset; + } + [[nodiscard]] constexpr pointer data() const noexcept { return packed ? packed->data() : nullptr; } @@ -97,36 +112,6 @@ private: difference_type offset; }; -template -[[nodiscard]] constexpr std::ptrdiff_t operator-(const sparse_set_iterator &lhs, const sparse_set_iterator &rhs) noexcept { - return rhs.index() - lhs.index(); -} - -template -[[nodiscard]] constexpr bool operator==(const sparse_set_iterator &lhs, const sparse_set_iterator &rhs) noexcept { - return lhs.index() == rhs.index(); -} - -template -[[nodiscard]] constexpr bool operator<(const sparse_set_iterator &lhs, const sparse_set_iterator &rhs) noexcept { - return lhs.index() > rhs.index(); -} - -template -[[nodiscard]] constexpr bool operator>(const sparse_set_iterator &lhs, const sparse_set_iterator &rhs) noexcept { - return rhs < lhs; -} - -template -[[nodiscard]] constexpr bool operator<=(const sparse_set_iterator &lhs, const sparse_set_iterator &rhs) noexcept { - return !(lhs > rhs); -} - -template -[[nodiscard]] constexpr bool operator>=(const sparse_set_iterator &lhs, const sparse_set_iterator &rhs) noexcept { - return !(lhs < rhs); -} - } // namespace internal /*! @endcond */