mercredi 29 avril 2015

An object containing a vector referring to another vector's content

My problem is hard to explain, so I'll take the scenario itself as example: I have a templated Matrix class, which is using a std::vector as storage.

What I'm looking for is having a "row", or "block" method, capable to return another Matrix with a smaller size, but referring to its parent.

With this piece of code:

Matrix<float> mat(2, 2);
// Filling the matrix
Matrix<float> row = mat.row(0); // returns a 1x2 matrix(row vector)
row[1] = 10; // Here I modify the row, which reflects the modifications in mat
std::cout << mat(0, 1); // prints 10

I have been thinking about multiple solutions but all of them have some non-negligible downsides. Do you have any ideas about how to achieve this? Thanks!

EDIT 1 : I forgot to precise, the behavior should be recursive, like getting a block of another block, etc.

Aucun commentaire:

Enregistrer un commentaire