view: stable single type view ::each(cb) function

This commit is contained in:
Michele Caini
2023-04-28 14:20:45 +02:00
parent 3b8d82330d
commit 17dc061490
2 changed files with 8 additions and 0 deletions

View File

@@ -850,6 +850,7 @@ public:
*/
template<typename Func>
void each(Func func) const {
if(view) {
if constexpr(is_applicable_v<Func, decltype(*each().begin())>) {
for(const auto pack: each()) {
std::apply(func, pack);
@@ -864,6 +865,7 @@ public:
}
}
}
}
/**
* @brief Returns an iterable object to use to _visit_ a view.

View File

@@ -94,10 +94,16 @@ TEST(SingleComponentView, InvalidView) {
ASSERT_EQ(iterable.begin(), iterable.end());
ASSERT_EQ(iterable.cbegin(), iterable.cend());
view.each([](const int &) { FAIL(); });
view.each([](const entt::entity, const int &) { FAIL(); });
entt::storage<int> storage;
view.storage(storage);
ASSERT_TRUE(view);
view.each([](const int &) { FAIL(); });
view.each([](const entt::entity, const int &) { FAIL(); });
}
TEST(SingleComponentView, Constructors) {