I am writing a c++ program which uses boost library for matrix operations. I have a need were by i have to dynamically expand the size of the initial matrix.
Example:
if my matrix size was:
matrix<float> m(3,3);
and later my matrix will expand and i’ll need a 4*4 matrix. The naive approach i could think of is allocate a new matrix with size 4,4 and and copy all elements of 3*3 matrix to it. Isn’t there any better way of doing this in boost?
Please, consider using the
resize()function: "The existing elements of the matrix are preseved (sic) when specified."Here is an example code from Boost.
This is one of ways.