Michele Caini 4 лет назад
Родитель
Сommit
4b9331f086
1 измененных файлов с 39 добавлено и 28 удалено
  1. 39 28
      src/entt/entity/sparse_set.hpp

+ 39 - 28
src/entt/entity/sparse_set.hpp

@@ -72,38 +72,10 @@ struct sparse_set_iterator final {
         return (*this + -value);
         return (*this + -value);
     }
     }
 
 
-    difference_type operator-(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
-        return other.index - index;
-    }
-
     [[nodiscard]] reference operator[](const difference_type value) const {
     [[nodiscard]] reference operator[](const difference_type value) const {
         return *operator+(value);
         return *operator+(value);
     }
     }
 
 
-    [[nodiscard]] bool operator==(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
-        return other.index == index;
-    }
-
-    [[nodiscard]] bool operator!=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
-        return !(*this == other);
-    }
-
-    [[nodiscard]] bool operator<(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
-        return index > other.index;
-    }
-
-    [[nodiscard]] bool operator>(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
-        return index < other.index;
-    }
-
-    [[nodiscard]] bool operator<=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
-        return !(*this > other);
-    }
-
-    [[nodiscard]] bool operator>=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
-        return !(*this < other);
-    }
-
     [[nodiscard]] pointer operator->() const {
     [[nodiscard]] pointer operator->() const {
         const auto pos = index - 1;
         const auto pos = index - 1;
         return packed->data() + pos;
         return packed->data() + pos;
@@ -113,11 +85,50 @@ struct sparse_set_iterator final {
         return *operator->();
         return *operator->();
     }
     }
 
 
+    [[nodiscard]] difference_type base() const ENTT_NOEXCEPT {
+        return index;
+    }
+
 private:
 private:
     const Container *packed;
     const Container *packed;
     difference_type index;
     difference_type index;
 };
 };
 
 
+template<typename Container>
+[[nodiscard]] auto operator-(const sparse_set_iterator<Container> &lhs, const sparse_set_iterator<Container> &rhs) ENTT_NOEXCEPT {
+    return rhs.base() - lhs.base();
+}
+
+template<typename Container>
+[[nodiscard]] bool operator==(const sparse_set_iterator<Container> &lhs, const sparse_set_iterator<Container> &rhs) ENTT_NOEXCEPT {
+    return lhs.base() == rhs.base();
+}
+
+template<typename Container>
+[[nodiscard]] bool operator!=(const sparse_set_iterator<Container> &lhs, const sparse_set_iterator<Container> &rhs) ENTT_NOEXCEPT {
+    return !(lhs == rhs);
+}
+
+template<typename Container>
+[[nodiscard]] bool operator<(const sparse_set_iterator<Container> &lhs, const sparse_set_iterator<Container> &rhs) ENTT_NOEXCEPT {
+    return lhs.base() > rhs.base();
+}
+
+template<typename Container>
+[[nodiscard]] bool operator>(const sparse_set_iterator<Container> &lhs, const sparse_set_iterator<Container> &rhs) ENTT_NOEXCEPT {
+    return lhs.base() < rhs.base();
+}
+
+template<typename Container>
+[[nodiscard]] bool operator<=(const sparse_set_iterator<Container> &lhs, const sparse_set_iterator<Container> &rhs) ENTT_NOEXCEPT {
+    return !(lhs > rhs);
+}
+
+template<typename Container>
+[[nodiscard]] bool operator>=(const sparse_set_iterator<Container> &lhs, const sparse_set_iterator<Container> &rhs) ENTT_NOEXCEPT {
+    return !(lhs < rhs);
+}
+
 } // namespace internal
 } // namespace internal
 
 
 /**
 /**