New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C++] Create reusable Iterator<T> interface #21956
Comments
Liya Fan / @liyafan82: What is the standard way to know if there is a next element in the iterator? |
Wes McKinney / @wesm: https://github.com/apache/arrow/blob/master/cpp/src/arrow/util/iterator.h I notice that I missed the virtual destructor. If this is the preferred Iterator interface, then I would suggest refactoring one or two of our ad hoc iterator classes in the codebase to use |
Ben Kietzman / @bkietz: |
Wes McKinney / @wesm: |
Liya Fan / @liyafan82:
|
Ben Kietzman / @bkietz: template <typename T>
class Iterator {
public:
virtual ~Iterator() = default;
virtual Status Next(T* value, bool* done) = 0;
} |
Wes McKinney / @wesm: |
Francois Saint-Jacques / @fsaintjacques:
|
Francois Saint-Jacques / @fsaintjacques: |
Antoine Pitrou / @pitrou: I also think it's essential to be able to return errors - either via As for signaling completion without consuming a value, well, the problem is that not all iterators may support that. Is there a use case where this matters? |
Micah Kornfield / @emkornfield:
Using StopIteration and Result I think you get something like: while (RETURN_IF_NOT_STOPPED_ERROR(v, iter.next()) { doSomethingWith(v) } Not sure if the macros to make that nice are even vaible.
"As for signaling completion without consuming a value, well, the problem is that not all iterators may support that. Is there a use case where this matters?" I think in many cases this can be solved with a "peek" style iterator?
|
Ben Kietzman / @bkietz: WRT easier iteration, we currently have ASSERT_OK(iter.Visit([&](T v) {
doSomethingWith(v);
return Status::OK();
})); |
Wes McKinney / @wesm: |
Antoine Pitrou / @pitrou: |
We have various iterator-like classes. I envision a reusable interface like
Reporter: Wes McKinney / @wesm
Related issues:
Note: This issue was originally created as ARROW-5508. Please see the migration documentation for further details.
The text was updated successfully, but these errors were encountered: