Michele Caini 7 лет назад
Родитель
Сommit
f0c11daa37

+ 3 - 3
src/entt/entity/registry.hpp

@@ -93,7 +93,7 @@ class registry {
     static void destroying(registry &reg, const Entity entity) {
         auto *handler = static_cast<handler_type<sizeof...(Component)> *>(reg.handlers[handler_family::type<Component...>].get());
         const sparse_set<Entity> &cpool = reg.pool<Comp>();
-        const auto last = *cpool.cbegin();
+        const auto last = *cpool.begin();
 
         if(handler->has(last)) {
             handler->get(last)[Index] = cpool.get(entity);
@@ -134,11 +134,11 @@ class registry {
 
         if(index != sizeof...(Indexes)) {
             auto *handler = static_cast<handler_type<sizeof...(Component)> *>(handlers[handler_family::type<Component...>].get());
-            auto cbegin = handler->sparse_set<Entity>::cbegin();
+            auto begin = handler->sparse_set<Entity>::begin();
             const auto &cpool = *pools[ctype];
 
             for(auto &&indexes: *handler) {
-                indexes[index] = cpool.get(*(cbegin++));
+                indexes[index] = cpool.get(*(begin++));
             }
         }
     }

+ 8 - 76
src/entt/entity/sparse_set.hpp

@@ -171,8 +171,6 @@ public:
     using size_type = std::size_t;
     /*! @brief Input iterator type. */
     using iterator_type = iterator;
-    /*! @brief Constant input iterator type. */
-    using const_iterator_type = iterator;
 
     /*! @brief Default constructor. */
     sparse_set() ENTT_NOEXCEPT = default;
@@ -278,41 +276,9 @@ public:
      *
      * @return An iterator to the first entity of the internal packed array.
      */
-    const_iterator_type cbegin() const ENTT_NOEXCEPT {
+    iterator_type begin() const ENTT_NOEXCEPT {
         const typename traits_type::difference_type pos = direct.size();
-        return const_iterator_type{&direct, pos};
-    }
-
-    /**
-     * @brief Returns an iterator to the beginning.
-     *
-     * The returned iterator points to the first entity of the internal packed
-     * array. If the sparse set is empty, the returned iterator will be equal to
-     * `end()`.
-     *
-     * @note
-     * Input iterators stay true to the order imposed by a call to `respect`.
-     *
-     * @return An iterator to the first entity of the internal packed array.
-     */
-    inline const_iterator_type begin() const ENTT_NOEXCEPT {
-        return cbegin();
-    }
-
-    /**
-     * @brief Returns an iterator to the beginning.
-     *
-     * The returned iterator points to the first entity of the internal packed
-     * array. If the sparse set is empty, the returned iterator will be equal to
-     * `end()`.
-     *
-     * @note
-     * Input iterators stay true to the order imposed by a call to `respect`.
-     *
-     * @return An iterator to the first entity of the internal packed array.
-     */
-    inline iterator_type begin() ENTT_NOEXCEPT {
-        return cbegin();
+        return iterator_type{&direct, pos};
     }
 
     /**
@@ -328,42 +294,8 @@ public:
      * @return An iterator to the element following the last entity of the
      * internal packed array.
      */
-    const_iterator_type cend() const ENTT_NOEXCEPT {
-        return const_iterator_type{&direct, {}};
-    }
-
-    /**
-     * @brief Returns an iterator to the end.
-     *
-     * The returned iterator points to the element following the last entity in
-     * the internal packed array. Attempting to dereference the returned
-     * iterator results in undefined behavior.
-     *
-     * @note
-     * Input iterators stay true to the order imposed by a call to `respect`.
-     *
-     * @return An iterator to the element following the last entity of the
-     * internal packed array.
-     */
-    inline const_iterator_type end() const ENTT_NOEXCEPT {
-        return cend();
-    }
-
-    /**
-     * @brief Returns an iterator to the end.
-     *
-     * The returned iterator points to the element following the last entity in
-     * the internal packed array. Attempting to dereference the returned
-     * iterator results in undefined behavior.
-     *
-     * @note
-     * Input iterators stay true to the order imposed by a call to `respect`.
-     *
-     * @return An iterator to the element following the last entity of the
-     * internal packed array.
-     */
-    inline iterator_type end() ENTT_NOEXCEPT {
-        return cend();
+    iterator_type end() const ENTT_NOEXCEPT {
+        return iterator_type{&direct, {}};
     }
 
     /**
@@ -509,8 +441,8 @@ public:
      * @param other The sparse sets that imposes the order of the entities.
      */
     void respect(const sparse_set &other) ENTT_NOEXCEPT {
-        auto from = other.cbegin();
-        auto to = other.cend();
+        const auto to = other.end();
+        auto from = other.begin();
 
         size_type pos = direct.size() - 1;
 
@@ -1045,8 +977,8 @@ public:
      * @param other The sparse sets that imposes the order of the entities.
      */
     void respect(const sparse_set<Entity> &other) ENTT_NOEXCEPT {
-        auto from = other.cbegin();
-        auto to = other.cend();
+        const auto to = other.end();
+        auto from = other.begin();
 
         size_type pos = underlying_type::size() - 1;
         const auto *local = underlying_type::data();

+ 19 - 19
src/entt/entity/view.hpp

@@ -102,7 +102,7 @@ class persistent_view final {
 
     template<typename Func, std::size_t... Indexes>
     void each(Func func, std::index_sequence<Indexes...>) const {
-        std::for_each(handler->view_type::cbegin(), handler->view_type::cend(), [func = std::move(func), raw = handler->cbegin(), this](const auto entity) mutable {
+        std::for_each(handler->view_type::begin(), handler->view_type::end(), [func = std::move(func), raw = handler->cbegin(), this](const auto entity) mutable {
             func(entity, pool<Component>()->raw()[(*raw)[Indexes]]...);
             ++raw;
         });
@@ -114,7 +114,7 @@ public:
     /*! @brief Unsigned integer type. */
     using size_type = typename view_type::size_type;
     /*! @brief Input iterator type. */
-    using iterator_type = typename view_type::const_iterator_type;
+    using iterator_type = typename view_type::iterator_type;
 
     /*! @brief Default copy constructor. */
     persistent_view(const persistent_view &) = default;
@@ -173,7 +173,7 @@ public:
      * @return An iterator to the first entity that has the given components.
      */
     iterator_type begin() const ENTT_NOEXCEPT {
-        return handler->view_type::cbegin();
+        return handler->view_type::begin();
     }
 
     /**
@@ -192,7 +192,7 @@ public:
      * given components.
      */
     iterator_type end() const ENTT_NOEXCEPT {
-        return handler->view_type::cend();
+        return handler->view_type::end();
     }
 
     /**
@@ -201,7 +201,7 @@ public:
      * @return The identifier that occupies the given position.
      */
     entity_type operator[](const size_type pos) const ENTT_NOEXCEPT {
-        return handler->view_type::cbegin()[pos];
+        return handler->view_type::begin()[pos];
     }
 
     /**
@@ -346,7 +346,7 @@ class view final {
     using component_iterator_type = decltype(std::declval<pool_type<Comp>>().begin());
 
     using view_type = sparse_set<Entity>;
-    using underlying_iterator_type = typename view_type::const_iterator_type;
+    using underlying_iterator_type = typename view_type::iterator_type;
     using unchecked_type = std::array<const view_type *, (sizeof...(Component) - 1)>;
     using pattern_type = std::tuple<pool_type<Component> *...>;
     using traits_type = entt_traits<Entity>;
@@ -461,11 +461,11 @@ class view final {
     template<typename Comp, typename Func, std::size_t... Indexes>
     void each(pool_type<Comp> *cpool, Func func, std::index_sequence<Indexes...>) const {
         const auto other = unchecked(cpool);
-        std::array<underlying_iterator_type, sizeof...(Indexes)> data{{std::get<Indexes>(other)->cbegin()...}};
+        std::array<underlying_iterator_type, sizeof...(Indexes)> data{{std::get<Indexes>(other)->begin()...}};
         const auto extent = std::min({ pool<Component>()->extent()... });
         auto raw = std::make_tuple(pool<Component>()->begin()...);
-        const auto end = cpool->view_type::cend();
-        auto begin = cpool->view_type::cbegin();
+        const auto end = cpool->view_type::end();
+        auto begin = cpool->view_type::begin();
 
         // we can directly use the raw iterators if pools are ordered
         while(((begin != end) && ... && (*begin == *(std::get<Indexes>(data)++)))) {
@@ -535,7 +535,7 @@ public:
      */
     iterator_type begin() const ENTT_NOEXCEPT {
         const auto *view = candidate();
-        return iterator_type{unchecked(view), view->cbegin(), view->cend()};
+        return iterator_type{unchecked(view), view->begin(), view->end()};
     }
 
     /**
@@ -555,7 +555,7 @@ public:
      */
     iterator_type end() const ENTT_NOEXCEPT {
         const auto *view = candidate();
-        return iterator_type{unchecked(view), view->cend(), view->cend()};
+        return iterator_type{unchecked(view), view->end(), view->end()};
     }
 
     /**
@@ -684,7 +684,7 @@ public:
     /*! @brief Unsigned integer type. */
     using size_type = typename pool_type::size_type;
     /*! @brief Input iterator type. */
-    using iterator_type = typename view_type::const_iterator_type;
+    using iterator_type = typename view_type::iterator_type;
 
     /*! @brief Default copy constructor. */
     view(const view &) = default;
@@ -759,7 +759,7 @@ public:
      * @return An iterator to the first entity that has the given component.
      */
     iterator_type begin() const ENTT_NOEXCEPT {
-        return pool->view_type::cbegin();
+        return pool->view_type::begin();
     }
 
     /**
@@ -778,7 +778,7 @@ public:
      * given component.
      */
     iterator_type end() const ENTT_NOEXCEPT {
-        return pool->view_type::cend();
+        return pool->view_type::end();
     }
 
     /**
@@ -787,7 +787,7 @@ public:
      * @return The identifier that occupies the given position.
      */
     entity_type operator[](const size_type pos) const ENTT_NOEXCEPT {
-        return pool->view_type::cbegin()[pos];
+        return pool->view_type::begin()[pos];
     }
 
     /**
@@ -836,7 +836,7 @@ public:
      */
     template<typename Func>
     void each(Func func) const {
-        std::for_each(pool->view_type::cbegin(), pool->view_type::cend(), [func = std::move(func), raw = pool->begin()](const auto entity) mutable {
+        std::for_each(pool->view_type::begin(), pool->view_type::end(), [func = std::move(func), raw = pool->begin()](const auto entity) mutable {
             func(entity, *(raw++));
         });
     }
@@ -1080,7 +1080,7 @@ class runtime_view {
     friend class registry<Entity>;
 
     using view_type = sparse_set<Entity>;
-    using underlying_iterator_type = typename view_type::const_iterator_type;
+    using underlying_iterator_type = typename view_type::iterator_type;
     using pattern_type = std::vector<const view_type *>;
     using extent_type = typename view_type::size_type;
     using traits_type = entt_traits<Entity>;
@@ -1237,7 +1237,7 @@ public:
         if(valid()) {
             const auto &pool = *pools.front();
             const auto * const *data = pools.data();
-            it = { pool.cbegin(), pool.cend(), data + 1, data + pools.size(), min() };
+            it = { pool.begin(), pool.end(), data + 1, data + pools.size(), min() };
         }
 
         return it;
@@ -1263,7 +1263,7 @@ public:
 
         if(valid()) {
             const auto &pool = *pools.front();
-            it = { pool.cend(), pool.cend(), nullptr, nullptr, min() };
+            it = { pool.end(), pool.end(), nullptr, nullptr, min() };
         }
 
         return it;

+ 1 - 46
test/entt/entity/sparse_set.cpp

@@ -101,51 +101,6 @@ TEST(SparseSetNoType, Iterator) {
     ASSERT_EQ(*begin.operator->(), 3);
 }
 
-TEST(SparseSetNoType, ConstIterator) {
-    using iterator_type = typename entt::sparse_set<std::uint64_t>::const_iterator_type;
-
-    entt::sparse_set<std::uint64_t> set;
-    set.construct(3);
-
-    iterator_type cend{set.cbegin()};
-    iterator_type cbegin{};
-    cbegin = set.cend();
-    std::swap(cbegin, cend);
-
-    ASSERT_EQ(cbegin, set.cbegin());
-    ASSERT_EQ(cend, set.cend());
-    ASSERT_NE(cbegin, cend);
-
-    ASSERT_EQ(cbegin++, set.cbegin());
-    ASSERT_EQ(cbegin--, set.cend());
-
-    ASSERT_EQ(cbegin+1, set.cend());
-    ASSERT_EQ(cend-1, set.cbegin());
-
-    ASSERT_EQ(++cbegin, set.cend());
-    ASSERT_EQ(--cbegin, set.cbegin());
-
-    ASSERT_EQ(cbegin += 1, set.cend());
-    ASSERT_EQ(cbegin -= 1, set.cbegin());
-
-    ASSERT_EQ(cbegin + (cend - cbegin), set.cend());
-    ASSERT_EQ(cbegin - (cbegin - cend), set.cend());
-
-    ASSERT_EQ(cend - (cend - cbegin), set.cbegin());
-    ASSERT_EQ(cend + (cbegin - cend), set.cbegin());
-
-    ASSERT_EQ(cbegin[0], *set.cbegin());
-
-    ASSERT_LT(cbegin, cend);
-    ASSERT_LE(cbegin, set.cbegin());
-
-    ASSERT_GT(cend, cbegin);
-    ASSERT_GE(cend, set.cend());
-
-    ASSERT_EQ(*cbegin, 3);
-    ASSERT_EQ(*cbegin.operator->(), 3);
-}
-
 TEST(SparseSetNoType, Data) {
     entt::sparse_set<std::uint64_t> set;
 
@@ -330,7 +285,7 @@ TEST(SparseSetNoType, CanModifyDuringIteration) {
 
     ASSERT_EQ(set.capacity(), entt::sparse_set<std::uint64_t>::size_type{1});
 
-    const auto it = set.cbegin();
+    const auto it = set.begin();
     set.reserve(entt::sparse_set<std::uint64_t>::size_type{2});
 
     ASSERT_EQ(set.capacity(), entt::sparse_set<std::uint64_t>::size_type{2});