Browse Source

view: ::size/::size_hint in_place support for single type views

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

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

@@ -660,9 +660,11 @@ public:
 
 
     /**
     /**
      * @brief Returns the number of entities that have the given element.
      * @brief Returns the number of entities that have the given element.
+     * @tparam Pol Dummy template parameter used for sfinae purposes only.
      * @return Number of entities that have the given element.
      * @return Number of entities that have the given element.
      */
      */
-    [[nodiscard]] size_type size() const noexcept {
+    template<typename..., deletion_policy Pol = Policy>
+    [[nodiscard]] std::enable_if_t<Pol != deletion_policy::in_place, size_type> size() const noexcept {
         if constexpr(Policy == deletion_policy::swap_and_pop) {
         if constexpr(Policy == deletion_policy::swap_and_pop) {
             return leading ? leading->size() : size_type{};
             return leading ? leading->size() : size_type{};
         } else {
         } else {
@@ -671,6 +673,16 @@ public:
         }
         }
     }
     }
 
 
+    /**
+     * @brief Estimates the number of entities iterated by the view.
+     * @tparam Pol Dummy template parameter used for sfinae purposes only.
+     * @return Estimated number of entities iterated by the view.
+     */
+    template<typename..., deletion_policy Pol = Policy>
+    [[nodiscard]] std::enable_if_t<Pol == deletion_policy::in_place, size_type> size_hint() const noexcept {
+        return leading ? leading->size() : size_type{};
+    }
+
     /**
     /**
      * @brief Checks whether a view is empty.
      * @brief Checks whether a view is empty.
      * @return True if the view is empty, false otherwise.
      * @return True if the view is empty, false otherwise.