From dcb5aed901d3d74fdc1e12a495ba36deff7e3dd2 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 2 May 2023 14:39:06 +0200 Subject: [PATCH] registry: lazily/partially initialize views in the ::view const function --- src/entt/entity/registry.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index f3e4ebec0..17ca32a59 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -1195,7 +1195,10 @@ public: template [[nodiscard]] basic_view, storage_for_type...>, exclude_t...>> view(exclude_t = exclude_t{}) const { - return {*assure>(), *assure>()..., *assure>()...}; + const auto cpools = std::make_tuple(assure>(), assure>()..., assure>()...); + basic_view, storage_for_type...>, exclude_t...>> elem{}; + std::apply([&elem](const auto *...curr) { ((curr ? elem.storage(*curr) : void()), ...); }, cpools); + return elem; } /*! @copydoc view */