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
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:
classExampleVisitor {
public:template <typename T>
Status Visit(const T& arr) {
/// Do stuff and save result to output_;returnStatus::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:
classExampleVisitorWithArg {
public:template <typename T>
Status Visit(const T& arr, std::shared_ptr<Array>* output) {
/// Do stuff and save result to output directly;returnStatus::OK();
}
};
ExampleVisitorWithArg visitor;
RETURN_NOT_OK(VisitArrayInline(*arr, &visitor, &output));
Component(s)
C++
The text was updated successfully, but these errors were encountered:
…t 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 <shangjin1997@gmail.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
Describe the enhancement requested
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:It will be more convenient to write a Visitor if the VisitArrayInline function supports additional args for the
Visit
method:Component(s)
C++
The text was updated successfully, but these errors were encountered: