I would like to translate some existing Matlab code that quite naturally uses a lot of multidimensional arrays and I wonder what are the possible options. I want the containers to have copy constructors, default constructors, if possible clear error messages at compilation, access via A[i][j]
and in general not to be troublesome. Preferably, they should use the std::move
operation for speed.
As far as I can see the options boils down to:
std::vector
iterated. It sure works, but it seems stupid to writestd::vector<std::vector<std::vector<double> > >
for a 3D array. I am also concerned with the overhead in speed and memory.The boost::multiarray and blitz::Array offer most of the functionality but fails at the copy constructor (see stackoverflow) at runtime. It is unclear to me if there are valid reasons for that.
The Eigen library seems to be very fast but it does not allow copy at all, and has no default constructor, which means that another container has to be used.
The
std::array
has the disadvantage that the size has to be known when the object is created, so there is no default constructors.
Is there a simpler multidimensional container satisfying all the requests but more frugal than iterated std::vector
?