view: added ::refresh function to reinitialize the leading pool

This commit is contained in:
Michele Caini
2022-09-21 15:42:38 +02:00
parent 699aa5cd96
commit c3dec4b04e
2 changed files with 12 additions and 2 deletions

View File

@@ -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.

View File

@@ -563,7 +563,7 @@ TEST(MultiComponentView, Handle) {
ASSERT_TRUE(handle.contains(entity));
ASSERT_EQ(&handle, &view.handle());
view = registry.view<int, char>();
view = view.refresh();
auto &&other = view.handle();
ASSERT_TRUE(other.empty());