You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4b48ecc
Browse filesBrowse the repository at this point in the historyBrowse files
GH-33607: [C++] Support optional additional arguments for inline visit functions (#33608)
# Which issue does this PR close?
Closes#33607
# Rationale for this change
Sometimes we need extra arguments for the `Visit` function, the most common of which is output parameters to save the result. For now, we need to have a member variable and a member function to get the result:
```cpp
class ExampleVisitor {
public:
template <typename T>
Status Visit(const T& arr) {
/// Do stuff and save result to output_;
return Status::OK();
}
std::shared_ptr<Array> GetOutput() { return output_; }
private:
std::shared_ptr<Array> output_;
};
ExampleVisitor visitor;
RETURN_NOT_OK(VisitArrayInline(*arr, &visitor));
*output = visitor.GetOutput();
```
It will be more convenient to write a Visitor if the VisitArrayInline function supports additional args for the `Visit` method:
```cpp
class ExampleVisitorWithArg {
public:
template <typename T>
Status Visit(const T& arr, std::shared_ptr<Array>* output) {
/// Do stuff and save result to output directly;
return Status::OK();
}
};
ExampleVisitorWithArg visitor;
RETURN_NOT_OK(VisitArrayInline(*arr, &visitor, &output));
```
# Are these changes tested?
Not sure if we need to explicitly test this feature, since no runtime behavior is changed. The existing tests all pass.
# Are there any user-facing changes?
There is a small chance, like in [diff.cc:402](https://github.com/apache/arrow/pull/33608/files#diff-ef9d394f251ee719f9896b864246bd97a81165c08195d4846d5d99e589e5c1c0L402), `VisitTypeInline` is declared as a friend function. The declaration needs to be changed. But I am not sure if any outside user would do this.
Authored-by: Jin Shang <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
0 commit comments