
AMDG Vladan Vidakovic wrote:
Hi, I'm learning about multi_arrays and have not been able to find much info about different ways of initializing them. In particular I'm interested in initializing a multi_array in the same way I can init a basic C/C++ array:
int array_2d[3][3] = { {1,2,3}, {2,3,4}, {3,4,5} };
That is impossible because multi_array is not an aggregate.
When I declare an analogous multi_array, the compiler (VC++ 8.0) complains about the third line:
typedef boost::multi_array< int, 2 > int_2d_array_t; boost::array< int_2d_array_t::index, 2 > shape = {{ 3, 3 }};
int_2d_array_t A(shape) = { {1,2,3}, {2,3,4}, {3,4,5} }; // error C2143: syntax error : missing ';' before '='
The online documentation only mentions initialization of individual elements (A[0][0][0] = 4;), but in doing it that way would be very tedious.
What alternatives are there?
Nothing really wonderful, I hate to say. I wish that Boost.Assign worked.
The best I can come up with is:
#include