diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 0691f8f49..bb9dc04e9 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -52,7 +52,9 @@ public: last{to}, pools{all_of}, filter{none_of} { - while(it != last && !valid()) { ++it; } + while(it != last && !valid()) { + ++it; + } } view_iterator &operator++() noexcept { @@ -295,6 +297,14 @@ public: return other; } + /** + * @brief Updates the internal leading view if required. + * @return A newly created and internally optimized view. + */ + [[nodiscard]] basic_view refresh() const noexcept { + return std::apply([](auto *...elem) { return basic_view{*elem...}; }, std::tuple_cat(pools, filter)); + } + /** * @brief Returns the leading storage of a view. * @return The leading storage of the view. diff --git a/test/entt/entity/view.cpp b/test/entt/entity/view.cpp index 633178b1d..f11d50061 100644 --- a/test/entt/entity/view.cpp +++ b/test/entt/entity/view.cpp @@ -563,7 +563,7 @@ TEST(MultiComponentView, Handle) { ASSERT_TRUE(handle.contains(entity)); ASSERT_EQ(&handle, &view.handle()); - view = registry.view(); + view = view.refresh(); auto &&other = view.handle(); ASSERT_TRUE(other.empty());