view: turn ::refresh into a self contained, non-const function

This commit is contained in:
Michele Caini
2023-04-18 13:00:59 +02:00
parent 15726218bd
commit 3882c7d9af
3 changed files with 10 additions and 10 deletions

View File

@@ -268,7 +268,7 @@ public:
: pools{&value...},
filter{&excl...},
view{std::get<0>(pools)} {
((view = value.size() < view->size() ? &value : view), ...);
refresh();
}
/**
@@ -301,12 +301,9 @@ 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, internal::filter_as_tuple<Exclude...>(filter)));
/*! @brief Updates the internal leading view if required. */
void refresh() noexcept {
std::apply([this](auto *...elem) { ((view = elem->size() < view->size() ? elem : view), ...); }, pools);
}
/**

View File

@@ -995,8 +995,11 @@ TEST(Registry, View) {
ASSERT_EQ(mview.size_hint(), 3u);
ASSERT_EQ(fview.size_hint(), 3u);
ASSERT_EQ(mview.refresh().size_hint(), 2u);
ASSERT_EQ(fview.refresh().size_hint(), 3u);
mview.refresh();
fview.refresh();
ASSERT_EQ(mview.size_hint(), 2u);
ASSERT_EQ(fview.size_hint(), 3u);
ASSERT_NE(mview.begin(), mview.end());
ASSERT_NE(fview.begin(), fview.end());

View File

@@ -582,7 +582,7 @@ TEST(MultiComponentView, Handle) {
ASSERT_TRUE(handle.contains(entity));
ASSERT_EQ(&handle, &view.handle());
view = view.refresh();
view.refresh();
auto &&other = view.handle();
ASSERT_TRUE(other.empty());