Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) boost::multi_array

 

boost::multi_array is a Boost container for storing elements similar to a multi-dimensional array.

 

#include <cassert>
#include <boost/multi_array.hpp>

int main ()
{
  //Determine boost::multi_array size
  const int maxx = 3;
  const int maxy = 4;
  const int maxz = 5;
  //The '3' determines v being 3-dimensional
  boost::multi_array<double, 3> v(boost::extents[maxx][maxy][maxz]);
  //Choose a random spot
  const int x = std::rand() % maxx;
  const int y = std::rand() % maxy;
  const int z = std::rand() % maxz;
  //Write to a random spot
  v[x][y][z] = x + y + z;
  //Read from to a random spot
  assert(v[x][y][z]==x+y+z);
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict