dhruv9vats commented on a change in pull request #11946:
URL: https://github.com/apache/arrow/pull/11946#discussion_r779597891
##########
File path: cpp/src/arrow/record_batch.h
##########
@@ -234,6 +234,67 @@ class ARROW_EXPORT RecordBatchReader {
return batch;
}
+ class RecordBatchReaderIterator {
+ public:
+ using iterator_category = std::input_iterator_tag;
+ using difference_type = std::ptrdiff_t;
+ using value_type = std::shared_ptr<RecordBatch>;
+ using pointer = value_type const*;
+ using reference = value_type const&;
+
+ RecordBatchReaderIterator() : batch_(RecordBatchEnd()), reader_(NULLPTR) {}
+
+ explicit RecordBatchReaderIterator(RecordBatchReader* reader)
+ : batch_(RecordBatchEnd()), reader_(reader) {
+ Next();
+ }
+
+ bool operator==(const RecordBatchReaderIterator& other) const {
+ return batch_ == other.batch_;
+ }
+
+ bool operator!=(const RecordBatchReaderIterator& other) const {
+ return !(*this == other);
+ }
+
+ Result<std::shared_ptr<RecordBatch>> operator*() {
+ ARROW_RETURN_NOT_OK(batch_.status());
+
+ return batch_;
+ }
+
+ RecordBatchReaderIterator& operator++() {
+ Next();
+ return *this;
+ }
+
+ RecordBatchReaderIterator operator++(int) {
+ RecordBatchReaderIterator tmp(*this);
+ Next();
+ return tmp;
+ }
+
+ private:
+ std::shared_ptr<RecordBatch> RecordBatchEnd() {
+ return std::shared_ptr<RecordBatch>(NULLPTR);
+ }
+
+ void Next() {
Review comment:
I've tried to add all the basic things you mentioned. But is this the
correct way to implement the `Next` function here, because it feels like
something is missing here?
Is there supposed to be an additional check here to see if the end has been
reached? (Sorry if I'm overlooking something obvious and this is a naive
question) @pitrou
--
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]