Search code examples
c++templatesboostboost-multi-array

Understanding the Boost MultiArray parameters


This is from the Boost docs and compiles without problems.

#include "boost/multi_array.hpp"

int main () {
    // Create a 3D array that is 3 x 4 x 2
    typedef boost::multi_array<double,3> array_type;
    typedef array_type::index index;
    array_type A(boost::extents[3][4][2]);
    return 0;
}

My question is: What is the second template parameter? It's not clear to me from the documentation. This code will only compile if it is set to 3.


Solution

  • It's how many dimensions you need.

    boost::extents[3][4][2] // we use 3 dimensions
    

    So if you change this number, you'll have to change this line to.