c++ - How can I use a std::valarray to store/manipulate a contiguous 2D array? -


How can I use std :: valarray to store / manipulate 2D arrays Am I

I want to see an example of a 2D array with the elements accessed by the row / column index. Something like this pseudo code:

  matrix (i, j) = 42;  

An example of starting an array like this would also be good.

I already know about Boost. Multira, Boost.ubl, and Blitz ++.

Feel free to answer why I should not use Valerre for my use case. However, I want to have a memory block (column x lines) for multi-dimensional array

Top off:

  template & lt; Square element_type & gt; Square matrix {public: matrix (size_t width, size_t height): m_stride (width), m_height (height), m_storage (width * height) {} element_type and operator () (size_t row, size_t column) {// column major return M_storage [std :: slice (column, m_height, m_stride)] [row]; // line major return m_storage [std :: slice (row, m_stride, m_height)] [column]; } Private: std :: valarray & lt; Element_type & gt; M_storage; Size_t_m_stride; Size_t m_height; };  

std :: valarray provides several interesting ways to access elements through slides, masks, multi-functional slices, or an induction table. For std :: slice_array , std :: gslice_array , std :: mask_array , and std :: indirect_array See more details.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -