Browse Source

view: further reduce instantiations

Michele Caini 2 years ago
parent
commit
7f531e5e2d
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/entt/entity/view.hpp

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

@@ -31,6 +31,13 @@ template<typename Type, std::size_t N, std::size_t... Index>
     return (!(filter[Index] && filter[Index]->contains(entt)) && ...);
 }
 
+template<typename Type, std::size_t N>
+[[nodiscard]] auto fully_initialized(const std::array<const Type *, N> &filter) noexcept {
+    std::size_t pos{};
+    for(; pos < N && filter[pos] != nullptr; ++pos) {}
+    return pos == N;
+}
+
 template<typename... Get, typename... Exclude, std::size_t... Index>
 [[nodiscard]] auto view_pack(const std::tuple<Get *...> value, const std::tuple<Exclude *...> excl, std::index_sequence<Index...>) {
     const auto pools = std::tuple_cat(value, excl);
@@ -454,8 +461,7 @@ public:
      * @return True if the view is fully initialized, false otherwise.
      */
     [[nodiscard]] explicit operator bool() const noexcept {
-        return std::apply([](const auto *...curr) { return ((curr != nullptr) && ...); }, pools)
-               && std::apply([](const auto *...curr) { return ((curr != nullptr) && ...); }, filter);
+        return std::apply([](const auto *...curr) { return ((curr != nullptr) && ...); }, pools) && internal::fully_initialized(filter);
     }
 
     /**