Skip to content

Latest commit

 

History

History
38 lines (21 loc) · 1.94 KB

CppBoostMulti_array.md

File metadata and controls

38 lines (21 loc) · 1.94 KB

 

 

 

 

 

 

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); }