Browse Source

group: extended_group_iterator::base to return the underlying iterator

Michele Caini 3 years ago
parent
commit
095ecf3142
3 changed files with 9 additions and 1 deletions
  1. 0 1
      TODO
  2. 5 0
      src/entt/entity/group.hpp
  3. 4 0
      test/entt/entity/group.cpp

+ 0 - 1
TODO

@@ -15,7 +15,6 @@ TODO (high prio):
 * check natvis files (periodically :)
 * check natvis files (periodically :)
 * remove the static storage from the const assure in the registry
 * remove the static storage from the const assure in the registry
 * pop_if to improve further destroying entities (drastically)
 * pop_if to improve further destroying entities (drastically)
-* add iterator_type/base to extended storage iterators (group)
 
 
 WIP:
 WIP:
 * get rid of observers, storage based views made them pointless - document alternatives
 * get rid of observers, storage based views made them pointless - document alternatives

+ 5 - 0
src/entt/entity/group.hpp

@@ -36,6 +36,7 @@ class extended_group_iterator<It, owned_t<Owned...>, get_t<Get...>> {
     }
     }
 
 
 public:
 public:
+    using iterator_type = It;
     using difference_type = std::ptrdiff_t;
     using difference_type = std::ptrdiff_t;
     using value_type = decltype(std::tuple_cat(std::make_tuple(*std::declval<It>()), std::declval<Owned>().get_as_tuple({})..., std::declval<Get>().get_as_tuple({})...));
     using value_type = decltype(std::tuple_cat(std::make_tuple(*std::declval<It>()), std::declval<Owned>().get_as_tuple({})..., std::declval<Get>().get_as_tuple({})...));
     using pointer = input_iterator_pointer<value_type>;
     using pointer = input_iterator_pointer<value_type>;
@@ -67,6 +68,10 @@ public:
         return operator*();
         return operator*();
     }
     }
 
 
+    constexpr iterator_type base() const noexcept {
+        return it;
+    }
+
     template<typename... Lhs, typename... Rhs>
     template<typename... Lhs, typename... Rhs>
     friend constexpr bool operator==(const extended_group_iterator<Lhs...> &, const extended_group_iterator<Rhs...> &) noexcept;
     friend constexpr bool operator==(const extended_group_iterator<Lhs...> &, const extended_group_iterator<Rhs...> &) noexcept;
 
 

+ 4 - 0
test/entt/entity/group.cpp

@@ -201,7 +201,9 @@ TEST(NonOwningGroup, Each) {
 
 
     auto it = iterable.begin();
     auto it = iterable.begin();
 
 
+    ASSERT_EQ(it.base(), group.begin());
     ASSERT_EQ((it++, ++it), iterable.end());
     ASSERT_EQ((it++, ++it), iterable.end());
+    ASSERT_EQ(it.base(), group.end());
 
 
     group.each([expected = 1](auto entt, int &ivalue, char &cvalue) mutable {
     group.each([expected = 1](auto entt, int &ivalue, char &cvalue) mutable {
         ASSERT_EQ(static_cast<int>(entt::to_integral(entt)), expected);
         ASSERT_EQ(static_cast<int>(entt::to_integral(entt)), expected);
@@ -875,7 +877,9 @@ TEST(OwningGroup, Each) {
 
 
     auto it = iterable.begin();
     auto it = iterable.begin();
 
 
+    ASSERT_EQ(it.base(), group.begin());
     ASSERT_EQ((it++, ++it), iterable.end());
     ASSERT_EQ((it++, ++it), iterable.end());
+    ASSERT_EQ(it.base(), group.end());
 
 
     group.each([expected = 1](auto entt, int &ivalue, char &cvalue) mutable {
     group.each([expected = 1](auto entt, int &ivalue, char &cvalue) mutable {
         ASSERT_EQ(static_cast<int>(entt::to_integral(entt)), expected);
         ASSERT_EQ(static_cast<int>(entt::to_integral(entt)), expected);