From 312c2b1cdfe17d799923d8daba9ea534f7264191 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 10 Jul 2024 08:52:56 +0200 Subject: [PATCH] view: drop empty func each support for non-empty types in single views --- TODO | 2 -- src/entt/entity/view.hpp | 28 ++++++++++------------------ test/entt/entity/view.cpp | 11 +++++------ 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/TODO b/TODO index 8c7d1b29a..5e7fd08b7 100644 --- a/TODO +++ b/TODO @@ -20,7 +20,6 @@ TODO: * view: update natvis as needed after the last rework, merge pools/filter in the same array, drop check (?) and turn view into a position * view: type-only view_iterator (dyn get/excl sizes), type-only basic_common_view (dyn get/excl sizes with pointer to array from derived) * combine version-mask-vs-version-bits tricks with reserved bits to allow things like enabling/disabling -* review all // NOLINT * self contained entity traits to avoid explicit specializations (ie enum constants) * auto type info data from types if present * test: push sharing types further @@ -38,7 +37,6 @@ TODO: * improve front (no multiple checks) and back (ie no contains) for multi-type view * cleanup common view from tricks to handle single swap-only and in-place, if constexpr branches * consider returning subrange for swap-only sparse sets or consider using filtered each for in-place storage (smilar to storage entity), cleanup views -* stop supporting func() for view::each (nonsense) * exploit ref/cref in any to avoid invoking the vtable if possible * review meta properties and details, maybe a dense map is too much * self assignment support for any and meta_any diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index c01154069..99b90d800 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -1002,35 +1002,27 @@ public: */ template void each(Func func) const { - if constexpr(is_applicable_veach().begin())>) { + if constexpr(is_applicable_v{}, std::declval().get({})))>) { for(const auto pack: each()) { std::apply(func, pack); } - } else if constexpr(std::is_invocable_vbegin())>) { - if constexpr(Get::storage_policy == deletion_policy::swap_and_pop || Get::storage_policy == deletion_policy::swap_only) { + } else if constexpr(Get::storage_policy == deletion_policy::swap_and_pop || Get::storage_policy == deletion_policy::swap_only) { + if constexpr(std::is_void_v) { + for(size_type pos = base_type::size(); pos; --pos) { + func(); + } + } else { if(const auto len = base_type::size(); len != 0u) { for(auto last = storage()->end(), first = last - len; first != last; ++first) { func(*first); } } - } else { - static_assert(Get::storage_policy == deletion_policy::in_place, "Unexpected storage policy"); - - for(const auto pack: each()) { - func(std::get<1>(pack)); - } } } else { - if constexpr(Get::storage_policy == deletion_policy::swap_and_pop || Get::storage_policy == deletion_policy::swap_only) { - for(size_type pos = base_type::size(); pos; --pos) { - func(); - } - } else { - static_assert(Get::storage_policy == deletion_policy::in_place, "Unexpected storage policy"); + static_assert(Get::storage_policy == deletion_policy::in_place, "Unexpected storage policy"); - for([[maybe_unused]] const auto entt: *this) { - func(); - } + for(const auto pack: each()) { + std::apply([&func](const auto, auto &&...elem) { func(std::forward(elem)...); }, pack); } } } diff --git a/test/entt/entity/view.cpp b/test/entt/entity/view.cpp index c96818160..76c612c73 100644 --- a/test/entt/entity/view.cpp +++ b/test/entt/entity/view.cpp @@ -401,17 +401,16 @@ TEST(SingleStorageView, StableType) { ASSERT_EQ(entt, entity[1u]); } - view.each([&entity](const auto entt, const auto &) { + view.each([&](const auto entt, const auto &elem) { + ASSERT_EQ(elem, view->get(entity[1u])); ASSERT_EQ(entt, entity[1u]); }); - view.each([check = view->get(entity[1u])](const auto &elem) { - ASSERT_EQ(elem, check); + view.each([&](const auto &elem) { + ASSERT_EQ(elem, view->get(entity[1u])); }); - view.each([&]() { - storage.erase(entity[1u]); - }); + storage.erase(view.begin(), view.end()); ASSERT_EQ(view.size_hint(), 2u); ASSERT_EQ(view->size(), 2u);