Просмотр исходного кода

view: stable single type view ::each(cb) function

Michele Caini 2 лет назад
Родитель
Сommit
17dc061490
2 измененных файлов с 8 добавлено и 0 удалено
  1. 2 0
      src/entt/entity/view.hpp
  2. 6 0
      test/entt/entity/view.cpp

+ 2 - 0
src/entt/entity/view.hpp

@@ -850,6 +850,7 @@ public:
      */
     template<typename Func>
     void each(Func func) const {
+        if(view) {
         if constexpr(is_applicable_v<Func, decltype(*each().begin())>) {
             for(const auto pack: each()) {
                 std::apply(func, pack);
@@ -864,6 +865,7 @@ public:
             }
         }
     }
+    }
 
     /**
      * @brief Returns an iterable object to use to _visit_ a view.

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

@@ -94,10 +94,16 @@ TEST(SingleComponentView, InvalidView) {
     ASSERT_EQ(iterable.begin(), iterable.end());
     ASSERT_EQ(iterable.cbegin(), iterable.cend());
 
+    view.each([](const int &) { FAIL(); });
+    view.each([](const entt::entity, const int &) { FAIL(); });
+
     entt::storage<int> storage;
     view.storage(storage);
 
     ASSERT_TRUE(view);
+
+    view.each([](const int &) { FAIL(); });
+    view.each([](const entt::entity, const int &) { FAIL(); });
 }
 
 TEST(SingleComponentView, Constructors) {