meta: make meta_range iterators return an id and meta object pair

This commit is contained in:
Michele Caini
2022-08-21 12:34:52 +02:00
parent 1581aa1cf5
commit a8eebcb0e2
3 changed files with 16 additions and 9 deletions

View File

@@ -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{};
}
/**

View File

@@ -3,6 +3,8 @@
#include <cstddef>
#include <iterator>
#include <utility>
#include "../core/fwd.hpp"
#include "../core/iterator.hpp"
namespace entt {
@@ -61,7 +63,7 @@ private:
template<typename Type, typename It>
struct meta_range_iterator final {
using difference_type = std::ptrdiff_t;
using value_type = Type;
using value_type = std::pair<id_type, Type>;
using pointer = input_iterator_pointer<value_type>;
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 {

View File

@@ -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<base_t>());
ASSERT_EQ(curr.first, entt::type_id<base_t>().hash());
ASSERT_EQ(curr.second, entt::resolve<base_t>());
}
}