Boost logo

Boost Users :

Subject: Re: [Boost-users] [Multi-Array] Coercion to multi_array_ref from array_view?
From: Ronald Garcia (rxg_at_[hidden])
Date: 2012-09-21 17:10:34


Hi Jason,

I have to admit, off the top of my head I can't remember if that was a design decision or if that was a rationale. Could you please file a report on the Boost Trac about this?

Thanks,
Ron

On Sep 20, 2012, at 10:25 AM, Jason Sewall wrote:

> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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