Parcourir la source

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

Michele Caini il y a 2 ans
Parent
commit
44ed10c50b
2 fichiers modifiés avec 8 ajouts et 0 suppressions
  1. 4 0
      src/entt/entity/view.hpp
  2. 4 0
      test/entt/entity/view.cpp

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

@@ -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.

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

@@ -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());