From 52fa6907647df8d2cfcce51900670dfb9a31aca9 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 29 Oct 2020 00:03:26 +0100 Subject: [PATCH] view: added use to set explicitly the type that should drive all iterations in a multi type view --- TODO | 5 ++--- src/entt/entity/view.hpp | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index f2ba93468..da5c7b968 100644 --- a/TODO +++ b/TODO @@ -17,11 +17,10 @@ - ... WIP: -* remove extended registry::remove, rename it to (basic) erase and document the handle way for extended operations -* make view pack work also with groups +* document the handle way for extended operations +* make view pack work also with groups, add multi-type iterator (not only input iterators) * add exclude-only views to combine with packs * deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views -* split basic_view and view_t like sfinae-friendly class * HP: write documentation for custom storages and views!! * view pack: plain function as an alias for operator|, reverse iterators, rbegin and rend * pagination doesn't work nicely across boundaries probably, give it a look. RO operations are fine, adding components maybe not. diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index bf1f41788..255b365be 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -318,6 +318,15 @@ public: /*! @brief Reverse iterator type. */ using reverse_iterator = view_iterator::reverse_iterator>; + /** + * @brief Forces the type to use to drive iterations. + * @tparam Comp Type of component to use to drive the iteration. + */ + template + void use() const ENTT_NOEXCEPT { + view = std::get *>(pools); + } + /** * @brief Estimates the number of entities iterated by the view. * @return Estimated number of entities iterated by the view. @@ -493,13 +502,13 @@ public: * * @sa each * - * @tparam Comp Type of component to use to enforce the iteration order. + * @tparam Comp Type of component to use to drive the iteration. * @tparam Func Type of the function object to invoke. * @param func A valid function object. */ template void each(Func func) const { - view = std::get *>(pools); + use(); traverse(std::move(func), return_type{}); } @@ -531,12 +540,12 @@ public: * * @sa each * - * @tparam Comp Type of component to use to enforce the iteration order. + * @tparam Comp Type of component to use to drive the iteration. * @return An iterable object to use to _visit_ the view. */ template [[nodiscard]] iterable_view each() const ENTT_NOEXCEPT { - view = std::get *>(pools); + use(); return iterable_view{*this}; }