One-line initialiser for Boost.MultiArray

后端 未结 3 655
被撕碎了的回忆
被撕碎了的回忆 2020-12-31 20:53

I have a n-dimensional Boost.MultiArray I initialize as follows:

const int n=3, size=4; //# of dimensions and size of one dimension
boost::multi_array

        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 21:15

    From the Boost Multi-Array documentation, yes, you can initialize it one line:

    typedef boost::multi_array array_type;
    typedef array_type::index index;
    array_type A(boost::extents[3][4][2]);
    

    The typedefs are for readability, one can just as easily do for your example:

    boost::multi_array arr(boost::extents[2][4]);
    

提交回复
热议问题