I'm learning C++, so please be patient with me.
I have a std::valarray
in which there are double
elements and I consider it as a 2D matrix.
class Matrix {
valarray<double> elems;
int r, c;
public:
/* type? operator[](int r) { return ? } */
//...
}
I want to overload the operator[]
, so that I can get a row of the matrix, and after that, I want have the m[r][c]
access operator.
Is there any way to get a row, as a sequence of double
using std::slice
in the valarray
, so that if I change a value, it is changed also in the matrix?
I've read this definition in valarray:
std::slice_array<T> operator[]( std::slice slicearr );
My operator[]
must have std::slice_array<double>&
as returned type?
Thanks.