How best to store a dynamic matrix: std::vector<std::vector<T>> , std::vector<std::vector<T>*> or std::vector<std::unique_ptr<std::vector<T>>> , where T - a) trivial type; b) non-trivial type T - a) trivial type; b) non-trivial type ?
2 answers
Actually, as they say, depends on ... Personally, I would prefer the first of the above options - because of the simplicity of the work, the natural reference to the elements through two indexing operations, the absence of overhead costs for indirect calls.
But, quite possibly, I would use some other (perhaps my own) option - if there was any information about the matrix - what operations are planned, dense / sparse, how important is efficiency at work, how often will (and whether) change the size of the matrix ...
How best to store a dynamic matrix
The matrix of any dimension is well displayed in a one-dimensional vector. Your task will be reduced to just playing with indexes.
std::unique_ptr) is usually simpler than regular pointers. - yrHeTaTeJlb