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 ref_array_2d;
void foo_ref(ref_array_2d ma)
{
ma[0][1] = 1.0;
}
int main()
{
typedef boost::multi_array 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::array_view<2ul>::type {aka
boost::detail::multi_array::multi_array_view}’ to
‘ref_array_2d {aka boost::multi_array_ref}’"
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?
Cheers,
Jason