Przeglądaj źródła

input_iterator_pointer: operator*

Michele Caini 3 lat temu
rodzic
commit
a6171551bd
2 zmienionych plików z 12 dodań i 0 usunięć
  1. 10 0
      src/entt/core/iterator.hpp
  2. 2 0
      test/entt/core/iterator.cpp

+ 10 - 0
src/entt/core/iterator.hpp

@@ -18,6 +18,8 @@ struct input_iterator_pointer final {
     using value_type = Type;
     /*! @brief Pointer type. */
     using pointer = Type *;
+    /*! @brief Reference type. */
+    using reference = Type &;
 
     /**
      * @brief Constructs a proxy object by move.
@@ -34,6 +36,14 @@ struct input_iterator_pointer final {
         return std::addressof(value);
     }
 
+    /**
+     * @brief Dereference operator for accessing wrapped values.
+     * @return A reference to the wrapped value.
+     */
+    [[nodiscard]] constexpr reference operator*() noexcept {
+        return value;
+    }
+
 private:
     Type value;
 };

+ 2 - 0
test/entt/core/iterator.cpp

@@ -16,6 +16,8 @@ TEST(InputIteratorPointer, Functionalities) {
 
     ASSERT_EQ(instance.value, 0);
     ASSERT_EQ(ptr->value, 42);
+    ASSERT_EQ(ptr->value, (*ptr).value);
+    ASSERT_EQ(ptr.operator->(), &ptr.operator*());
 }
 
 TEST(IotaIterator, Functionalities) {