diff --git a/src/entt/meta/internal.hpp b/src/entt/meta/internal.hpp index ec0cf823c..4ca20d741 100644 --- a/src/entt/meta/internal.hpp +++ b/src/entt/meta/internal.hpp @@ -128,53 +128,51 @@ struct meta_type_node { template -struct meta_iterator { - using difference_type = std::ptrdiff_t; - using value_type = Node; - using pointer = value_type *; - using reference = value_type &; - using iterator_category = std::forward_iterator_tag; +class meta_range { + struct range_iterator { + using difference_type = std::ptrdiff_t; + using value_type = Node; + using pointer = value_type *; + using reference = value_type &; + using iterator_category = std::forward_iterator_tag; - meta_iterator() ENTT_NOEXCEPT = default; + range_iterator() ENTT_NOEXCEPT = default; - meta_iterator(Node *head) ENTT_NOEXCEPT - : node{head} - {} + range_iterator(Node *head) ENTT_NOEXCEPT + : node{head} + {} - meta_iterator & operator++() ENTT_NOEXCEPT { - return node = node->next, *this; - } + range_iterator & operator++() ENTT_NOEXCEPT { + return node = node->next, *this; + } - meta_iterator operator++(int) ENTT_NOEXCEPT { - meta_iterator orig = *this; - return operator++(), orig; - } + range_iterator operator++(int) ENTT_NOEXCEPT { + range_iterator orig = *this; + return operator++(), orig; + } - [[nodiscard]] bool operator==(const meta_iterator &other) const ENTT_NOEXCEPT { - return other.node == node; - } + [[nodiscard]] bool operator==(const range_iterator &other) const ENTT_NOEXCEPT { + return other.node == node; + } - [[nodiscard]] bool operator!=(const meta_iterator &other) const ENTT_NOEXCEPT { - return !(*this == other); - } + [[nodiscard]] bool operator!=(const range_iterator &other) const ENTT_NOEXCEPT { + return !(*this == other); + } - [[nodiscard]] pointer operator->() const ENTT_NOEXCEPT { - return node; - } + [[nodiscard]] pointer operator->() const ENTT_NOEXCEPT { + return node; + } - [[nodiscard]] reference operator*() const ENTT_NOEXCEPT { - return *operator->(); - } + [[nodiscard]] reference operator*() const ENTT_NOEXCEPT { + return *operator->(); + } -private: - Node *node{nullptr}; -}; + private: + Node *node{nullptr}; + }; - -template -struct meta_range { - using iterator = meta_iterator; - using const_iterator = meta_iterator; +public: + using iterator = range_iterator; meta_range() ENTT_NOEXCEPT = default; @@ -182,30 +180,14 @@ struct meta_range { : node{head} {} - iterator begin() ENTT_NOEXCEPT { + iterator begin() const ENTT_NOEXCEPT { return iterator{node}; } - const_iterator begin() const ENTT_NOEXCEPT { - return const_iterator{node}; - } - - const_iterator cbegin() const ENTT_NOEXCEPT { - return begin(); - } - - iterator end() ENTT_NOEXCEPT { + iterator end() const ENTT_NOEXCEPT { return iterator{}; } - const_iterator end() const ENTT_NOEXCEPT { - return const_iterator{}; - } - - const_iterator cend() const ENTT_NOEXCEPT { - return end(); - } - private: Node *node{nullptr}; }; diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 042c5b70a..56d12a0cc 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -642,7 +642,7 @@ struct meta_ctor { */ [[nodiscard]] meta_prop prop(meta_any key) const { internal::meta_range range{node->prop}; - return std::find_if(range.cbegin(), range.cend(), [&key](const auto &curr) { return curr.key() == key; }).operator->(); + return std::find_if(range.begin(), range.end(), [&key](const auto &curr) { return curr.key() == key; }).operator->(); } /** @@ -789,7 +789,7 @@ struct meta_data { */ [[nodiscard]] meta_prop prop(meta_any key) const { internal::meta_range range{node->prop}; - return std::find_if(range.cbegin(), range.cend(), [&key](const auto &curr) { return curr.key() == key; }).operator->(); + return std::find_if(range.begin(), range.end(), [&key](const auto &curr) { return curr.key() == key; }).operator->(); } /** @@ -909,7 +909,7 @@ struct meta_func { */ [[nodiscard]] meta_prop prop(meta_any key) const { internal::meta_range range{node->prop}; - return std::find_if(range.cbegin(), range.cend(), [&key](const auto &curr) { return curr.key() == key; }).operator->(); + return std::find_if(range.begin(), range.end(), [&key](const auto &curr) { return curr.key() == key; }).operator->(); } /** @@ -931,7 +931,7 @@ class meta_type { [[nodiscard]] auto ctor(std::index_sequence) const { internal::meta_range range{node->ctor}; - return std::find_if(range.cbegin(), range.cend(), [](const auto &candidate) { + return std::find_if(range.begin(), range.end(), [](const auto &candidate) { return candidate.size == sizeof...(Args) && ([](auto *from, auto *to) { return (from->type_id == to->type_id) || internal::find_if<&node_type::base>([to](const auto *curr) { return curr->type()->type_id == to->type_id; }, from) diff --git a/src/entt/meta/range.hpp b/src/entt/meta/range.hpp index 45f326a1f..ddfbcab2d 100644 --- a/src/entt/meta/range.hpp +++ b/src/entt/meta/range.hpp @@ -8,90 +8,56 @@ namespace entt { -/** - * @brief Meta iterator to use to iterate all types of meta objects. - * @tparam Type Type of meta objects returned by the iterator. - */ -template -struct meta_iterator { - /*! @brief Signed integer type. */ - using difference_type = std::ptrdiff_t; - /*! @brief Type of meta objects returned by the iterator. */ - using value_type = Type; - /*! @brief Pointer type, `void` on purpose. */ - using pointer = void; - /*! @brief Type of proxy object. */ - using reference = value_type; - /*! @brief Iterator category. */ - using iterator_category = std::input_iterator_tag; - /*! @brief Node type. */ - using node_type = typename Type::node_type; - - /*! @brief Default constructor. */ - meta_iterator() ENTT_NOEXCEPT = default; - - /** - * @brief Constructs a meta iterator from a given node. - * @param head The underlying node with which to construct the iterator. - */ - meta_iterator(node_type *head) ENTT_NOEXCEPT - : it{head} - {} - - /*! @brief Pre-increment operator. @return This iterator. */ - meta_iterator & operator++() ENTT_NOEXCEPT { - return ++it, *this; - } - - /*! @brief Post-increment operator. @return A copy of this iterator. */ - meta_iterator operator++(int) ENTT_NOEXCEPT { - meta_iterator orig = *this; - return ++it, orig; - } - - /** - * @brief Indirection operator. - * @return A proxy object to the meta item pointed-to by the iterator. - */ - [[nodiscard]] reference operator*() const ENTT_NOEXCEPT { - return it.operator->(); - } - - /** - * @brief Checks if two meta iterators refer to the same meta object. - * @param other The meta iterator with which to compare. - * @return True if the two meta iterators refer to the same meta object, - * false otherwise. - */ - [[nodiscard]] bool operator==(const meta_iterator &other) const ENTT_NOEXCEPT { - return other.it == it; - } - - /** - * @brief Checks if two meta iterators refer to the same meta object. - * @param other The meta iterator with which to compare. - * @return False if the two meta iterators refer to the same meta object, - * true otherwise. - */ - [[nodiscard]] bool operator!=(const meta_iterator &other) const ENTT_NOEXCEPT { - return !(*this == other); - } - -private: - internal::meta_iterator it{}; -}; - - /** * @brief Iterable range to use to iterate all types of meta objects. * @tparam Type Type of meta objects iterated. */ template -struct meta_range { +class meta_range { + struct range_iterator { + using difference_type = std::ptrdiff_t; + using value_type = Type; + using pointer = void; + using reference = value_type; + using iterator_category = std::input_iterator_tag; + using node_type = typename Type::node_type; + + range_iterator() ENTT_NOEXCEPT = default; + + range_iterator(node_type *head) ENTT_NOEXCEPT + : it{head} + {} + + range_iterator & operator++() ENTT_NOEXCEPT { + return ++it, *this; + } + + range_iterator operator++(int) ENTT_NOEXCEPT { + range_iterator orig = *this; + return ++it, orig; + } + + [[nodiscard]] reference operator*() const ENTT_NOEXCEPT { + return it.operator->(); + } + + [[nodiscard]] bool operator==(const range_iterator &other) const ENTT_NOEXCEPT { + return other.it == it; + } + + [[nodiscard]] bool operator!=(const range_iterator &other) const ENTT_NOEXCEPT { + return !(*this == other); + } + + private: + typename internal::meta_range::iterator it{}; + }; + +public: /*! @brief Node type. */ using node_type = typename Type::node_type; /*! @brief Input iterator type. */ - using iterator = meta_iterator; + using iterator = range_iterator; /*! @brief Default constructor. */ meta_range() ENTT_NOEXCEPT = default; diff --git a/src/entt/meta/resolve.hpp b/src/entt/meta/resolve.hpp index 44a708aa5..84662286b 100644 --- a/src/entt/meta/resolve.hpp +++ b/src/entt/meta/resolve.hpp @@ -55,7 +55,7 @@ template [[deprecated("use std::find_if and entt::meta_range instead")]] [[nodiscard]] meta_type resolve_if(Func func) ENTT_NOEXCEPT { internal::meta_range range{*internal::meta_context::global()}; - return std::find_if(range.cbegin(), range.cend(), [&func](const auto &curr) { return func(meta_type{&curr}); }).operator->(); + return std::find_if(range.begin(), range.end(), [&func](const auto &curr) { return func(meta_type{&curr}); }).operator->(); } @@ -66,7 +66,7 @@ template */ [[nodiscard]] inline meta_type resolve_id(const id_type id) ENTT_NOEXCEPT { internal::meta_range range{*internal::meta_context::global()}; - return std::find_if(range.cbegin(), range.cend(), [id](const auto &curr) { return curr.id == id; }).operator->(); + return std::find_if(range.begin(), range.end(), [id](const auto &curr) { return curr.id == id; }).operator->(); } @@ -77,7 +77,7 @@ template */ [[nodiscard]] inline meta_type resolve_type(const id_type id) ENTT_NOEXCEPT { internal::meta_range range{*internal::meta_context::global()}; - return std::find_if(range.cbegin(), range.cend(), [id](const auto &curr) { return curr.type_id == id; }).operator->(); + return std::find_if(range.begin(), range.end(), [id](const auto &curr) { return curr.type_id == id; }).operator->(); }