|
Boost Users : |
Subject: [Boost-users] [Multi-Array] Coercion to multi_array_ref from array_view?
From: Jason Sewall (jasonsewall_at_[hidden])
Date: 2012-09-20 13:25:31
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?
Cheers,
Jason
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net