Browse Source

view: stable multi type view ::size_hint function

Michele Caini 2 years ago
parent
commit
c79c109b77
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

@@ -379,7 +379,7 @@ public:
      * @return Estimated number of entities iterated by the view.
      * @return Estimated number of entities iterated by the view.
      */
      */
     [[nodiscard]] size_type size_hint() const noexcept {
     [[nodiscard]] size_type size_hint() const noexcept {
-        return view->size();
+        return view ? view->size() : size_type{};
     }
     }
 
 
     /**
     /**

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

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