diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 0169f6c64..b39b940ce 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -390,12 +390,15 @@ public: {} /** - * @brief Forces the type to use to drive iterations. + * @brief Creates a new view driven by a given type in its iterations. * @tparam Comp Type of component to use to drive the iteration. + * @return A new view driven by the given type in its iterations. */ template - void use() const ENTT_NOEXCEPT { - view = std::get *>(pools); + [[nodiscard]] basic_view use() const ENTT_NOEXCEPT { + basic_view other{*this}; + other.view = std::get *>(pools); + return other; } /** @@ -641,9 +644,9 @@ public: friend auto operator|(const basic_view, exclude_t> &, const basic_view, exclude_t> &); private: - const std::tuple *...> pools; - const std::array filter; - mutable const basic_common_type *view; + std::tuple *...> pools; + std::array filter; + const basic_common_type *view; }; @@ -963,8 +966,8 @@ public: friend auto operator|(const basic_view, exclude_t> &, const basic_view, exclude_t> &); private: - const std::tuple pools; - const std::tuple<> filter; + std::tuple pools; + std::tuple<> filter; }; diff --git a/test/entt/entity/view.cpp b/test/entt/entity/view.cpp index c3fca909e..c40f35e81 100644 --- a/test/entt/entity/view.cpp +++ b/test/entt/entity/view.cpp @@ -1033,7 +1033,7 @@ TEST(MultiComponentView, StableType) { ASSERT_EQ(view.size_hint(), 1u); - view.use(); + view = view.use(); ASSERT_EQ(view.size_hint(), 2u); ASSERT_FALSE(view.contains(entity));