From a8eebcb0e29b595e5d73667dd6fa525aaf4b2d23 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sun, 21 Aug 2022 12:34:52 +0200 Subject: [PATCH] meta: make meta_range iterators return an id and meta object pair --- src/entt/meta/meta.hpp | 16 ++++++++++------ src/entt/meta/range.hpp | 6 ++++-- test/entt/meta/meta_type.cpp | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 9dac217eb..b6eff921b 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -1202,7 +1202,7 @@ public: } for(auto &&curr: base()) { - if(auto &&elem = curr.data(id); elem) { + if(auto &&elem = curr.second.data(id); elem) { return elem; } } @@ -1295,13 +1295,17 @@ public: * @return A wrapper containing the returned value, if any. */ meta_any invoke(const id_type id, meta_handle instance, meta_any *const args, const size_type sz) const { - const auto *candidate = old_lookup<&node_type::func>(args, sz, id); - - for(auto it = base().begin(), last = base().end(); it != last && !candidate; ++it) { - candidate = it->old_lookup<&node_type::func>(args, sz, id); + if(const auto *candidate = old_lookup<&node_type::func>(args, sz, id); candidate) { + return candidate->invoke(std::move(instance), args); } - return candidate ? candidate->invoke(std::move(instance), args) : meta_any{}; + for(auto &&curr: base()) { + if(auto res = curr.second.invoke(id, instance->as_ref(), args, sz); res) { + return res; + } + } + + return meta_any{}; } /** diff --git a/src/entt/meta/range.hpp b/src/entt/meta/range.hpp index 2a12a4248..d8dbfdc1e 100644 --- a/src/entt/meta/range.hpp +++ b/src/entt/meta/range.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include "../core/fwd.hpp" #include "../core/iterator.hpp" namespace entt { @@ -61,7 +63,7 @@ private: template struct meta_range_iterator final { using difference_type = std::ptrdiff_t; - using value_type = Type; + using value_type = std::pair; using pointer = input_iterator_pointer; using reference = value_type; using iterator_category = std::input_iterator_tag; @@ -82,7 +84,7 @@ struct meta_range_iterator final { } [[nodiscard]] reference operator*() const noexcept { - return &it->second; + return std::make_pair(it->first, &it->second); } [[nodiscard]] pointer operator->() const noexcept { diff --git a/test/entt/meta/meta_type.cpp b/test/entt/meta/meta_type.cpp index c861bf79f..769a8acae 100644 --- a/test/entt/meta/meta_type.cpp +++ b/test/entt/meta/meta_type.cpp @@ -297,7 +297,8 @@ TEST_F(MetaType, Base) { ASSERT_NE(type.base().cbegin(), type.base().cend()); for(auto curr: type.base()) { - ASSERT_EQ(curr, entt::resolve()); + ASSERT_EQ(curr.first, entt::type_id().hash()); + ASSERT_EQ(curr.second, entt::resolve()); } }