Browse Source

meta: add meta_range::operator->

Michele Caini 4 years ago
parent
commit
c51bec0034
2 changed files with 9 additions and 4 deletions
  1. 6 1
      src/entt/meta/range.hpp
  2. 3 3
      test/entt/meta/meta_range.cpp

+ 6 - 1
src/entt/meta/range.hpp

@@ -3,6 +3,7 @@
 
 #include <cstddef>
 #include <iterator>
+#include "../core/iterator.hpp"
 
 namespace entt {
 
@@ -16,7 +17,7 @@ class meta_range {
     struct range_iterator {
         using difference_type = std::ptrdiff_t;
         using value_type = Type;
-        using pointer = void;
+        using pointer = input_iterator_proxy<value_type>;
         using reference = value_type;
         using iterator_category = std::input_iterator_tag;
         using node_type = Node;
@@ -39,6 +40,10 @@ class meta_range {
             return it;
         }
 
+        [[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
+            return operator*();
+        }
+
         [[nodiscard]] bool operator==(const range_iterator &other) const ENTT_NOEXCEPT {
             return other.it == it;
         }

+ 3 - 3
test/entt/meta/meta_range.cpp

@@ -28,9 +28,9 @@ TEST_F(MetaRange, Range) {
     ASSERT_TRUE(it != range.end());
     ASSERT_FALSE(it == range.end());
 
-    ASSERT_EQ((*it).info(), entt::resolve<double>().info());
-    ASSERT_EQ((*(++it)).info(), entt::resolve("int"_hs).info());
-    ASSERT_EQ((*it++).info(), entt::resolve<int>().info());
+    ASSERT_EQ(it->info(), entt::resolve<double>().info());
+    ASSERT_EQ((++it)->info(), entt::resolve("int"_hs).info());
+    ASSERT_EQ((it++)->info(), entt::resolve<int>().info());
 
     ASSERT_EQ(it, range.end());
 }