#include #include #include typedef boost::multi_array_types::index_range range; void fill_array(boost::detail::multi_array::multi_array_view a) { for (int i = 0; i < a.shape()[0]; ++i) { a[i] = 3.14159; } } inline void fill_array(boost::multi_array_ref &a) { fill_array(a[boost::indices[range()]]); } int main() { const int dim1(2); const int dim2(3); boost::multi_array foo1d(boost::extents[dim1]); boost::multi_array foo2d(boost::extents[dim1][dim2]); fill_array(foo1d); // still worky, but in a different way std::cout << "foo1d[0] = " << foo1d[0] << std::endl; boost::multi_array::array_view<1 >::type view1 = foo2d[boost::indices[range()][0]]; fill_array(view1); // still worky std::cout << "foo2d[0][0] = " << foo2d[0][0] << std::endl; foo2d[0][0] = -999.0; fill_array(foo2d[boost::indices[range()][0]]); // now worky std::cout << "foo2d[0][0] = " << foo2d[0][0] << std::endl; return 0; }