How can I use a std::valarray to store/manipulate a 2D array?
I’d like to see an example of a 2D array with elements accessed by row/column indices. Something like this pseudo code:
matrix(i,j) = 42;
An example of how to initialize such an array would also be nice.
I’m already aware of Boost.MultiArray, Boost.uBlas, and Blitz++.
Feel free to answer why I shouldn’t use valarray for my use case. However, I want the memory for the multidimensional array to be a contiguous (columns x rows) block. No Java-style nested arrays.
Off the top of my head:
std::valarrayprovides many interesting ways to access elements, via slices, masks, multidimentional slices, or an indirection table. Seestd::slice_array,std::gslice_array,std::mask_array, andstd::indirect_arrayfor more details.