Browse Source

view: ::empty support for in-place

Michele Caini 1 year ago
parent
commit
ce543cf3fb
1 changed files with 9 additions and 2 deletions
  1. 9 2
      src/entt/entity/view.hpp

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

@@ -685,10 +685,17 @@ public:
 
 
     /**
     /**
      * @brief Checks whether a view is empty.
      * @brief Checks whether a view is empty.
+     * @tparam Pol Dummy template parameter used for sfinae purposes only.
      * @return True if the view is empty, false otherwise.
      * @return True if the view is empty, false otherwise.
      */
      */
-    [[nodiscard]] bool empty() const noexcept {
-        return (size() == 0u);
+    template<typename..., deletion_policy Pol = Policy>
+    [[nodiscard]] std::enable_if_t<Pol != deletion_policy::in_place, bool> empty() const noexcept {
+        if constexpr(Policy == deletion_policy::swap_and_pop) {
+            return !leading || leading->empty();
+        } else {
+            static_assert(Policy == deletion_policy::swap_only, "Unexpected storage policy");
+            return !leading || (leading->free_list() == 0u);
+        }
     }
     }
 
 
     /**
     /**