diff --git a/src/entt/entity/runtime_view.hpp b/src/entt/entity/runtime_view.hpp index 56f40a045..450f0339d 100644 --- a/src/entt/entity/runtime_view.hpp +++ b/src/entt/entity/runtime_view.hpp @@ -65,8 +65,8 @@ class basic_runtime_view { using direct_type = std::vector *>; - iterator(const direct_type *all, underlying_iterator_type curr) ENTT_NOEXCEPT - : pools{all}, + iterator(const direct_type &all, underlying_iterator_type curr) ENTT_NOEXCEPT + : pools{&all}, it{curr} { if(it != (*pools)[0]->end() && !valid()) { @@ -187,7 +187,7 @@ public: iterator_type it{}; if(valid()) { - it = { &pools, pools[0]->begin() }; + it = { pools, pools[0]->begin() }; } return it; @@ -212,7 +212,7 @@ public: iterator_type it{}; if(valid()) { - it = { &pools, pools[0]->end() }; + it = { pools, pools[0]->end() }; } return it; diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index 18ae55b41..bd782718c 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -58,8 +58,8 @@ class sparse_set { using direct_type = std::vector; using index_type = typename traits_type::difference_type; - iterator(const direct_type *ref, const index_type idx) ENTT_NOEXCEPT - : direct{ref}, index{idx} + iterator(const direct_type &ref, const index_type idx) ENTT_NOEXCEPT + : direct{&ref}, index{idx} {} public: @@ -95,7 +95,8 @@ class sparse_set { } iterator operator+(const difference_type value) const ENTT_NOEXCEPT { - return iterator{direct, index-value}; + iterator copy = *this; + return (copy += value); } iterator & operator-=(const difference_type value) ENTT_NOEXCEPT { @@ -297,7 +298,7 @@ public: */ iterator_type begin() const ENTT_NOEXCEPT { const typename traits_type::difference_type pos = direct.size(); - return iterator_type{&direct, pos}; + return iterator_type{direct, pos}; } /** @@ -315,7 +316,7 @@ public: * internal packed array. */ iterator_type end() const ENTT_NOEXCEPT { - return iterator_type{&direct, {}}; + return iterator_type{direct, {}}; } /** diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 08411cf45..416105918 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -57,8 +57,8 @@ class storage: public sparse_set { using instance_type = std::conditional_t, std::vector>; using index_type = typename traits_type::difference_type; - iterator(instance_type *ref, const index_type idx) ENTT_NOEXCEPT - : instances{ref}, index{idx} + iterator(instance_type &ref, const index_type idx) ENTT_NOEXCEPT + : instances{&ref}, index{idx} {} public: @@ -94,7 +94,8 @@ class storage: public sparse_set { } iterator operator+(const difference_type value) const ENTT_NOEXCEPT { - return iterator{instances, index-value}; + iterator copy = *this; + return (copy += value); } iterator & operator-=(const difference_type value) ENTT_NOEXCEPT { @@ -221,7 +222,7 @@ public: */ const_iterator_type cbegin() const ENTT_NOEXCEPT { const typename traits_type::difference_type pos = underlying_type::size(); - return const_iterator_type{&instances, pos}; + return const_iterator_type{instances, pos}; } /*! @copydoc cbegin */ @@ -232,7 +233,7 @@ public: /*! @copydoc begin */ iterator_type begin() ENTT_NOEXCEPT { const typename traits_type::difference_type pos = underlying_type::size(); - return iterator_type{&instances, pos}; + return iterator_type{instances, pos}; } /** @@ -250,7 +251,7 @@ public: * given type. */ const_iterator_type cend() const ENTT_NOEXCEPT { - return const_iterator_type{&instances, {}}; + return const_iterator_type{instances, {}}; } /*! @copydoc cend */ @@ -260,7 +261,7 @@ public: /*! @copydoc end */ iterator_type end() ENTT_NOEXCEPT { - return iterator_type{&instances, {}}; + return iterator_type{instances, {}}; } /** diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 8640820a1..a49682535 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -81,8 +81,8 @@ class basic_view, Component...> { class iterator final { friend class basic_view, Component...>; - iterator(const sparse_set *candidate, unchecked_type other, filter_type ignore, underlying_iterator_type curr) ENTT_NOEXCEPT - : view{candidate}, + iterator(const sparse_set &candidate, unchecked_type other, filter_type ignore, underlying_iterator_type curr) ENTT_NOEXCEPT + : view{&candidate}, unchecked{other}, filter{ignore}, it{curr} @@ -154,16 +154,16 @@ class basic_view, Component...> { : pools{&component..., &epool...} {} - const sparse_set * candidate() const ENTT_NOEXCEPT { - return std::min({ static_cast *>(std::get *>(pools))... }, [](const auto *lhs, const auto *rhs) { + const sparse_set & candidate() const ENTT_NOEXCEPT { + return *std::min({ static_cast *>(std::get *>(pools))... }, [](const auto *lhs, const auto *rhs) { return lhs->size() < rhs->size(); }); } - unchecked_type unchecked(const sparse_set *view) const { + unchecked_type unchecked(const sparse_set &view) const { std::size_t pos{}; unchecked_type other{}; - ((std::get *>(pools) == view ? nullptr : (other[pos++] = std::get *>(pools))), ...); + ((std::get *>(pools) == &view ? nullptr : (other[pos++] = std::get *>(pools))), ...); return other; } @@ -306,9 +306,9 @@ public: * @return An iterator to the first entity that has the given components. */ iterator_type begin() const { - const auto *view = candidate(); + const auto &view = candidate(); const filter_type ignore{std::get *>(pools)...}; - return iterator_type{view, unchecked(view), ignore, view->begin()}; + return iterator_type{view, unchecked(view), ignore, view.begin()}; } /** @@ -327,9 +327,9 @@ public: * given components. */ iterator_type end() const { - const auto *view = candidate(); + const auto &view = candidate(); const filter_type ignore{std::get *>(pools)...}; - return iterator_type{view, unchecked(view), ignore, view->end()}; + return iterator_type{view, unchecked(view), ignore, view.end()}; } /** @@ -359,9 +359,9 @@ public: * iterator otherwise. */ iterator_type find(const entity_type entt) const { - const auto *view = candidate(); + const auto &view = candidate(); const filter_type ignore{std::get *>(pools)...}; - iterator_type it{view, unchecked(view), ignore, view->find(entt)}; + iterator_type it{view, unchecked(view), ignore, view.find(entt)}; return (it != end() && *it == entt) ? it : end(); } @@ -430,8 +430,8 @@ public: */ template void each(Func func) const { - const auto *view = candidate(); - ((std::get *>(pools) == view ? each(std::move(func)) : void()), ...); + const auto &view = candidate(); + ((std::get *>(pools) == &view ? each(std::move(func)) : void()), ...); } /**