Specify the length of all arrays in boost::multi_array

52 views Asked by At

I have a probably stupid question, but I am trying to define a 8x3 array (each row is an array of 3 xyz-indices of a cell, there are 8 cells in total) using boost::multi_array. My question is, is there any way shorter/simpler than typing [DIM] 8 times like this:

static const int DIM = 3;
static const int CELL = 8;    
boost::multi_array<double, CELL> ii(boost::extents[DIM][DIM][DIM][DIM][DIM][DIM][DIM][DIM]);

to declare my array? Thanks a ton!

1

There are 1 answers

0
sehe On

boost::extents is just a generator, and you can use any compatible ExtentList model instead ¹:

boost::array<size_t, 8> dims;
std::fill(dims.begin(), dims.end(), DIM);

You could conceivably write your own model that doesn't require the backing storage for each dimension.

¹ See http://www.boost.org/doc/libs/1_63_0/libs/utility/Collection.html