felipecrv commented on code in PR #41824:
URL: https://github.com/apache/arrow/pull/41824#discussion_r1624687585


##########
cpp/src/arrow/util/iterator.h:
##########
@@ -105,9 +105,18 @@ class Iterator : public 
util::EqualityComparable<Iterator<T>> {
   Iterator() : ptr_(NULLPTR, [](void*) {}) {}
 
   /// \brief Return the next element of the sequence, 
IterationTraits<T>::End() when the
-  /// iteration is completed. Calling this on a default constructed Iterator
-  /// will result in undefined behavior.
-  Result<T> Next() { return next_(ptr_.get()); }
+  /// iteration is completed.
+  Result<T> Next() {
+    if (ptr_) {
+      auto next_result = next_(ptr_.get());
+      if (next_result.ok() && IsIterationEnd(next_result.ValueUnsafe())) {

Review Comment:
   @kou @bkietz This extra check and release should be the responsibility of 
the underlying iterator instead of forcing every abstract iterator to behave 
this way.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to