From d1073bb181f8aee7d9acf08fd459ad3446cc1a39 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 3 Jul 2024 10:28:31 +0200 Subject: [PATCH] view: ::size/::size_hint in_place support for single type views --- src/entt/entity/view.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 7dc19b0b6..833910b6b 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -660,9 +660,11 @@ public: /** * @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. */ - [[nodiscard]] size_type size() const noexcept { + template + [[nodiscard]] std::enable_if_t size() const noexcept { if constexpr(Policy == deletion_policy::swap_and_pop) { return leading ? leading->size() : size_type{}; } 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 + [[nodiscard]] std::enable_if_t size_hint() const noexcept { + return leading ? leading->size() : size_type{}; + } + /** * @brief Checks whether a view is empty. * @return True if the view is empty, false otherwise.