Opened 10 years ago

#7405 new Feature Requests

Coercion to multi_array_ref from array_view

Reported by: Jason Sewall <jasonsewall@…> Owned by: Ronald Garcia
Milestone: To Be Determined Component: multi_array
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:

Description

I'd like to have functions that can be passed references to arrays of a given storage type and rank. Take a look at the following code:

template <class A> void foo_duck(A ma) {

ma[0][1] = 1.0;

}

typedef boost::multi_array_ref<double, 2> ref_array_2d; void foo_ref(ref_array_2d ma) {

ma[0][1] = 1.0;

}

int main() {

typedef boost::multi_array<double, 3> array_3d; typedef boost::multi_array_types::index_range range;

array_3d A(boost::extents[3][4][4]); array_3d::array_view<2>::type slice = A[boost::indices[1][range()][range()]];

foo_duck(slice); foo_ref(slice);

return 0;

}

foo_duck works fine, but foo_ref does not; I get a compiler error (gcc 4.6.3, boost 1.47) like so: "error: could not convert ‘slice’ from ‘boost::multi_array<double, 3ul>::array_view<2ul>::type {aka boost::detail::multi_array::multi_array_view<double, 2ul>}’ to ‘ref_array_2d {aka boost::multi_array_ref<double, 2ul>}’"

I suspect, without having looked at the code itself, that multi_array_ref was never designed to be coerced from array_view, but I don't understand why. Is there a solution to my foo_ref problem that doesn't involve moving all such functions to headers and templating them?

Change History (0)

Note: See TracTickets for help on using tickets.