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

*: revert unnecessary changes ¯\_(ツ)_/¯

Michele Caini 4 лет назад
Родитель
Сommit
efaa3f9e55
4 измененных файлов с 68 добавлено и 103 удалено
  1. 6 12
      src/entt/entity/runtime_view.hpp
  2. 24 35
      src/entt/entity/sparse_set.hpp
  3. 32 44
      src/entt/meta/meta.hpp
  4. 6 12
      src/entt/meta/range.hpp

+ 6 - 12
src/entt/entity/runtime_view.hpp

@@ -76,8 +76,12 @@ public:
         return *operator->();
     }
 
-    [[nodiscard]] iterator_type base() const ENTT_NOEXCEPT {
-        return it;
+    [[nodiscard]] bool operator==(const runtime_view_iterator &other) const ENTT_NOEXCEPT {
+        return it == other.it;
+    }
+
+    [[nodiscard]] bool operator!=(const runtime_view_iterator &other) const ENTT_NOEXCEPT {
+        return !(*this == other);
     }
 
 private:
@@ -87,16 +91,6 @@ private:
     bool no_tombstone_check;
 };
 
-template<typename Type>
-[[nodiscard]] bool operator==(const runtime_view_iterator<Type> &lhs, const runtime_view_iterator<Type> &rhs) ENTT_NOEXCEPT {
-    return lhs.base() == rhs.base();
-}
-
-template<typename Type>
-[[nodiscard]] bool operator!=(const runtime_view_iterator<Type> &lhs, const runtime_view_iterator<Type> &rhs) ENTT_NOEXCEPT {
-    return !(lhs == rhs);
-}
-
 } // namespace internal
 
 /**

+ 24 - 35
src/entt/entity/sparse_set.hpp

@@ -85,49 +85,38 @@ struct sparse_set_iterator final {
         return *operator->();
     }
 
-    [[nodiscard]] difference_type base() const ENTT_NOEXCEPT {
-        return index;
+    [[nodiscard]] difference_type operator-(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
+        return other.index - index;
     }
 
-private:
-    const Container *packed;
-    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();
-}
+    [[nodiscard]] bool operator==(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
+        return index == other.index;
+    }
 
-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();
-}
+    [[nodiscard]] bool operator!=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
+        return !(*this == other);
+    }
 
-template<typename Container>
-[[nodiscard]] bool operator!=(const sparse_set_iterator<Container> &lhs, const sparse_set_iterator<Container> &rhs) ENTT_NOEXCEPT {
-    return !(lhs == rhs);
-}
+    [[nodiscard]] bool operator<(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
+        return index > other.index;
+    }
 
-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();
-}
+    [[nodiscard]] bool operator>(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
+        return index < other.index;
+    }
 
-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();
-}
+    [[nodiscard]] bool operator<=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
+        return !(*this > other);
+    }
 
-template<typename Container>
-[[nodiscard]] bool operator<=(const sparse_set_iterator<Container> &lhs, const sparse_set_iterator<Container> &rhs) ENTT_NOEXCEPT {
-    return !(lhs > rhs);
-}
+    [[nodiscard]] bool operator>=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
+        return !(*this < other);
+    }
 
-template<typename Container>
-[[nodiscard]] bool operator>=(const sparse_set_iterator<Container> &lhs, const sparse_set_iterator<Container> &rhs) ENTT_NOEXCEPT {
-    return !(lhs < rhs);
-}
+private:
+    const Container *packed;
+    difference_type index;
+};
 
 } // namespace internal
 

+ 32 - 44
src/entt/meta/meta.hpp

@@ -1536,6 +1536,24 @@ public:
         return static_cast<bool>(handle);
     }
 
+    /**
+     * @brief Checks if two iterators refer to the same element.
+     * @param other The iterator with which to compare.
+     * @return True if the iterators refer to the same element, false otherwise.
+     */
+    [[nodiscard]] bool operator==(const meta_iterator &other) const ENTT_NOEXCEPT {
+        return handle == other.handle;
+    }
+
+    /**
+     * @brief Checks if two iterators refer to the same element.
+     * @param other The iterator with which to compare.
+     * @return False if the iterators refer to the same element, true otherwise.
+     */
+    [[nodiscard]] bool operator!=(const meta_iterator &other) const ENTT_NOEXCEPT {
+        return !(*this == other);
+    }
+
     /**
      * @brief Returns the underlying iterator.
      * @return The underlying iterator.
@@ -1549,26 +1567,6 @@ private:
     any handle{};
 };
 
-/**
- * @brief Checks if two iterators refer to the same element.
- * @param lhs An iterator to compare.
- * @param rhs An iterator with which to compare.
- * @return True if the iterators refer to the same element, false otherwise.
- */
-[[nodiscard]] inline bool operator==(const typename meta_sequence_container::iterator &lhs, const typename meta_sequence_container::iterator &rhs) ENTT_NOEXCEPT {
-    return lhs.base() == rhs.base();
-}
-
-/**
- * @brief Checks if two iterators refer to the same element.
- * @param lhs An iterator to compare.
- * @param rhs An iterator with which to compare.
- * @return False if the iterators refer to the same element, true otherwise.
- */
-[[nodiscard]] inline bool operator!=(const typename meta_sequence_container::iterator &lhs, const typename meta_sequence_container::iterator &rhs) ENTT_NOEXCEPT {
-    return !(lhs == rhs);
-}
-
 /**
  * @brief Returns the meta value type of a container.
  * @return The meta value type of the container.
@@ -1746,11 +1744,21 @@ public:
     }
 
     /**
-     * @brief Returns the underlying iterator.
-     * @return The underlying iterator.
+     * @brief Checks if two iterators refer to the same element.
+     * @param other The iterator with which to compare.
+     * @return True if the iterators refer to the same element, false otherwise.
      */
-    any base() const ENTT_NOEXCEPT {
-        return handle.as_ref();
+    [[nodiscard]] bool operator==(const meta_iterator &other) const ENTT_NOEXCEPT {
+        return handle == other.handle;
+    }
+
+    /**
+     * @brief Checks if two iterators refer to the same element.
+     * @param other The iterator with which to compare.
+     * @return False if the iterators refer to the same element, true otherwise.
+     */
+    [[nodiscard]] bool operator!=(const meta_iterator &other) const ENTT_NOEXCEPT {
+        return !(*this == other);
     }
 
 private:
@@ -1758,26 +1766,6 @@ private:
     any handle{};
 };
 
-/**
- * @brief Checks if two iterators refer to the same element.
- * @param lhs An iterator to compare.
- * @param rhs An iterator with which to compare.
- * @return True if the iterators refer to the same element, false otherwise.
- */
-[[nodiscard]] inline bool operator==(const typename meta_associative_container::iterator &lhs, const typename meta_associative_container::iterator &rhs) ENTT_NOEXCEPT {
-    return lhs.base() == rhs.base();
-}
-
-/**
- * @brief Checks if two iterators refer to the same element.
- * @param lhs An iterator to compare.
- * @param rhs An iterator with which to compare.
- * @return False if the iterators refer to the same element, true otherwise.
- */
-[[nodiscard]] inline bool operator!=(const typename meta_associative_container::iterator &lhs, const typename meta_associative_container::iterator &rhs) ENTT_NOEXCEPT {
-    return !(lhs == rhs);
-}
-
 /**
  * @brief Returns true if a container is also key-only, false otherwise.
  * @return True if the associative container is also key-only, false otherwise.

+ 6 - 12
src/entt/meta/range.hpp

@@ -45,24 +45,18 @@ struct meta_range_iterator {
         return operator*();
     }
 
-    [[nodiscard]] const node_type *base() const ENTT_NOEXCEPT {
-        return it;
+    [[nodiscard]] bool operator==(const meta_range_iterator &other) const ENTT_NOEXCEPT {
+        return it == other.it;
+    }
+
+    [[nodiscard]] bool operator!=(const meta_range_iterator &other) const ENTT_NOEXCEPT {
+        return !(*this == other);
     }
 
 private:
     node_type *it{};
 };
 
-template<typename Type, typename Node>
-[[nodiscard]] bool operator==(const meta_range_iterator<Type, Node> &lhs, const meta_range_iterator<Type, Node> &rhs) ENTT_NOEXCEPT {
-    return lhs.base() == rhs.base();
-}
-
-template<typename Type, typename Node>
-[[nodiscard]] bool operator!=(const meta_range_iterator<Type, Node> &lhs, const meta_range_iterator<Type, Node> &rhs) ENTT_NOEXCEPT {
-    return !(lhs == rhs);
-}
-
 } // namespace internal
 
 /**