diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 78858ccda..207f2f09d 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -1495,7 +1495,7 @@ public: * @param iter The actual iterator with which to build the meta iterator. */ template - meta_iterator(It iter) + explicit meta_iterator(It iter) : vtable{&basic_vtable}, handle{std::move(iter)} {} @@ -1510,24 +1510,6 @@ public: return ++(*this), orig; } - /** - * @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 Indirection operator for accessing the pointed opaque object. * @return The element to which the iterator points. @@ -1567,6 +1549,26 @@ 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. @@ -1717,24 +1719,6 @@ public: return ++(*this), orig; } - /** - * @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 Indirection operator for accessing the pointed opaque object. * @return The element to which the iterator points. @@ -1761,11 +1745,39 @@ public: return static_cast(handle); } + /** + * @brief Returns the underlying iterator. + * @return The underlying iterator. + */ + any base() const ENTT_NOEXCEPT { + return handle.as_ref(); + } + private: vtable_type *vtable{}; 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.