diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 890a810b8..e9d87be12 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -61,7 +61,7 @@ template class view_iterator final { template - friend class extended_view_iterator; + friend struct extended_view_iterator; using iterator_type = Type::const_iterator; using iterator_traits = std::iterator_traits; @@ -138,13 +138,7 @@ template } template -class extended_view_iterator final { - template - [[nodiscard]] auto dereference(std::index_sequence) const noexcept { - return std::tuple_cat(std::make_tuple(*it), static_cast(const_cast *>(std::get(it.pools)))->get_as_tuple(*it)...); - } - -public: +struct extended_view_iterator final { using iterator_type = It; using value_type = decltype(std::tuple_cat(std::make_tuple(*std::declval()), std::declval().get_as_tuple({})...)); using pointer = input_iterator_pointer; @@ -169,7 +163,9 @@ public: } [[nodiscard]] reference operator*() const noexcept { - return dereference(std::index_sequence_for{}); + return [this](std::index_sequence) { + return std::tuple_cat(std::make_tuple(*it), static_cast(const_cast *>(std::get(it.pools)))->get_as_tuple(*it)...); + }(std::index_sequence_for{}); } [[nodiscard]] pointer operator->() const noexcept { @@ -439,11 +435,6 @@ class basic_view, exclude_t, std::enable_if_t<(sizeof. template static constexpr std::size_t index_of = type_list_index_v, type_list>; - template - [[nodiscard]] auto get(const base_type::entity_type entt, std::index_sequence) const noexcept { - return std::tuple_cat(storage()->get_as_tuple(entt)...); - } - template [[nodiscard]] auto dispatch_get(const std::tuple &curr) const { if constexpr(Curr == Other) { @@ -454,7 +445,7 @@ class basic_view, exclude_t, std::enable_if_t<(sizeof. } template - void each(Func &func, std::index_sequence) const { + void each(Func func, std::index_sequence) const { for(const auto curr: storage()->each()) { if(const auto entt = std::get<0>(curr); (!internal::tombstone_check_v || (entt != tombstone)) && ((Curr == Index || base_type::pool_at(Index)->contains(entt)) && ...) && base_type::none_of(entt)) { if constexpr(is_applicable_v{}, std::declval().get({})))>) { @@ -466,13 +457,6 @@ class basic_view, exclude_t, std::enable_if_t<(sizeof. } } - template - void pick_and_each(Func &func, std::index_sequence seq) const { - if(const auto *view = base_type::handle(); view != nullptr) { - ((view == base_type::pool_at(Index) ? each(func, seq) : void()), ...); - } - } - public: /*! @brief Common type among all storage types. */ using common_type = base_type::common_type; @@ -607,7 +591,9 @@ public: template [[nodiscard]] decltype(auto) get(const entity_type entt) const { if constexpr(sizeof...(Index) == 0) { - return get(entt, std::index_sequence_for{}); + return [this, entt](std::index_sequence) { + return std::tuple_cat(storage()->get_as_tuple(entt)...); + }(std::index_sequence_for{}); } else if constexpr(sizeof...(Index) == 1) { return (storage()->get(entt), ...); } else { @@ -632,7 +618,11 @@ public: */ template void each(Func func) const { - pick_and_each(func, std::index_sequence_for{}); + [this, &func](std::index_sequence seq) { + if(const auto *view = base_type::handle(); view != nullptr) { + ((view == base_type::pool_at(Index) ? each(std::move(func), seq) : void()), ...); + } + }(std::index_sequence_for{}); } /**