Skip to content

function takes either array or a view #75

Description

@nbecker

I tried coding this to find max_element using a binary search:

template<typename flt_t>
flt_t max_element2 (nd::Array<flt_t,1,1> const& in) {
  if (boost::size(in) == 1)
    return in[0];
  else {
    flt_t a = max_element2 (in[nd::view(0,boost::size(in)/2)]);
    flt_t b = max_element2 (in[nd::view(boost::size(in)/2)()]);
    return std::max (a, b);
  }
}

But it doesn't compile, because the recursive call passing a view doesn't match the function sig. I also tried ArrayRef, but same result. What is the correct way to code this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions