view: stable single type view ::begin/::end functions

This commit is contained in:
Michele Caini
2023-04-27 08:59:50 +02:00
parent b7a485767f
commit 26930633f0
2 changed files with 5 additions and 2 deletions

View File

@@ -695,7 +695,7 @@ public:
* @return An iterator to the first entity of the view.
*/
[[nodiscard]] iterator begin() const noexcept {
return view->begin();
return view ? view->begin() : iterator{};
}
/**
@@ -708,7 +708,7 @@ public:
* @return An iterator to the entity following the last entity of the view.
*/
[[nodiscard]] iterator end() const noexcept {
return view->end();
return view ? view->end() : iterator{};
}
/**

View File

@@ -80,6 +80,9 @@ TEST(SingleComponentView, InvalidView) {
ASSERT_TRUE(view.empty());
ASSERT_FALSE(view.contains(entt::null));
ASSERT_EQ(view.begin(), typename decltype(view)::iterator{});
ASSERT_EQ(view.begin(), view.end());
entt::storage<int> storage;
view.storage(storage);