view: stable multi type view ::find/::back/::front functions

This commit is contained in:
Michele Caini
2023-04-28 15:55:33 +02:00
parent 1b22809412
commit 44ed10c50b
2 changed files with 8 additions and 0 deletions

View File

@@ -423,11 +423,15 @@ public:
* otherwise.
*/
[[nodiscard]] entity_type back() const noexcept {
if(view) {
auto it = view->rbegin();
for(const auto last = view->rend(); it != last && !contains(*it); ++it) {}
return it == view->rend() ? null : *it;
}
return null;
}
/**
* @brief Finds an entity.
* @param entt A valid identifier.

View File

@@ -632,6 +632,10 @@ TEST(MultiComponentView, InvalidView) {
ASSERT_EQ(view.size_hint(), 0u);
ASSERT_FALSE(view.contains(entt::null));
ASSERT_EQ(view.find(entt::null), view.end());
ASSERT_EQ(view.front(), static_cast<entt::entity>(entt::null));
ASSERT_EQ(view.back(), static_cast<entt::entity>(entt::null));
ASSERT_EQ(view.begin(), typename decltype(view)::iterator{});
ASSERT_EQ(view.begin(), view.end());