Skip to content

[C++] Support optional additional arguments for inline visit functions #33607

Closed

Description

@js8544

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:

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:

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));

Component(s)

C++

Activity

  1. added a commit that references this issue on Jan 11, 2023
  2. added a commit that references this issue on Jan 16, 2023
  3. added this to the 11.0.0 milestone on Jan 16, 2023
  4. pitrou commented on Jan 16, 2023

    @pitrou
    Member

    Issue resolved by pull request 33608
    #33608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions