How to assign / copy a Boost::multi_array

后端 未结 1 874
-上瘾入骨i
-上瘾入骨i 2021-02-14 20:17

I want to assign a copy of a boost::multi_array. How can I do this. The object where I want to assign it to has been initialized with the default constructors.

This code

1条回答
  •  [愿得一人]
    2021-02-14 20:34

    You should resize m_f before assigning. It could look like in the following sample:

    void set_f(boost::multi_array &f) {
        std::vector ex;
        const size_t* shape = f.shape();
        ex.assign( shape, shape+f.num_dimensions() );
        m_f.resize( ex );
        m_f = f;
    }
    

    May be there is a better way. Conversion short to char will be implicit. You should consider using std::transform if you want explicit conversion.

    0 讨论(0)
提交回复
热议问题