[Boost-bugs] [Boost C++ Libraries] #7405: Coercion to multi_array_ref from array_view

Subject: [Boost-bugs] [Boost C++ Libraries] #7405: Coercion to multi_array_ref from array_view
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-09-21 22:10:52


#7405: Coercion to multi_array_ref from array_view
--------------------------------------------------+-------------------------
 Reporter: Jason Sewall <jasonsewall@…> | Owner: garcia
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: multi_array
  Version: Boost 1.47.0 | Severity: Problem
 Keywords: |
--------------------------------------------------+-------------------------
 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?

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7405>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC