Browse Source

view: stable single type view ::size function

Michele Caini 2 years ago
parent
commit
41c9a32f31
2 changed files with 3 additions and 1 deletions
  1. 1 1
      src/entt/entity/view.hpp
  2. 2 0
      test/entt/entity/view.cpp

+ 1 - 1
src/entt/entity/view.hpp

@@ -675,7 +675,7 @@ public:
      * @return Number of entities that have the given component.
      */
     [[nodiscard]] size_type size() const noexcept {
-        return view->size();
+        return view ? view->size() : size_type{};
     }
 
     /**

+ 2 - 0
test/entt/entity/view.cpp

@@ -76,6 +76,8 @@ TEST(SingleComponentView, InvalidView) {
 
     ASSERT_FALSE(view);
 
+    ASSERT_EQ(view.size(), 0u);
+
     entt::storage<int> storage;
     view.storage(storage);