Say I\'ve got an N-dimensional boost::multi_array (of type int for simplicity), where N
is known at compile time but can vary (i.e. is a non-type template param
There is a lack of simple boost multi array examples. So here is a very simple example of how to fill a boost multi array using indexes and how to read all the entries using a single pointer.
typedef boost::multi_array array_type;
typedef array_type::index index;
array_type A(boost::extents[3][2]);
// ------> x
// | 0 2 4
// | 1 3 5
// v
// y
double value = 0;
for(index x = 0; x < 3; ++x)
for(index y = 0; y < 2; ++y)
A[x][y] = value++;
double* it = A.origin();
double* end = A.origin() + A.num_elements();
for(; it != end; ++it){
std::cout << *it << " ";
}
// -> 0 1 2 3 4 5