convert int to const int

Dec 27, 2012 at 4:01pm
Hi !!!

I work on FMatrix to use the wonderful function 'svd' but it's a template whitch is : FMatrix < type, cinst int N, const int M> N and M are the dimensions of the matrix.

The problem is that i make a lot of calculs, I create a special vector and then I need to use my svd function on a FMatrix<float, vector.size(), vector.size()>
But size return a int and the template need a const int.
How to convert vector.size() to a const int N that i could use as my matrix dimensions as FMatrix <float, N, N>?

Thanks for help,
Last edited on Dec 27, 2012 at 4:01pm
Dec 27, 2012 at 4:37pm
Template parameters are compile-time constants. Either switch to a matrix library that allows defining matrix sizes at run time (I thought all of them did), or determine your size at compile time.
Dec 28, 2012 at 6:28pm
I can't switch to an other library since I need the function svd witch needs a FMatrix.
Dec 28, 2012 at 6:38pm
You cannot, simply. FMatrix needs a constant, known-at-compile-time, value. std::vector::size is not known at compile time, so it cannot be used with FMatrix.
If you have the source for the svd function, you can adapt it to be used with another matrix library.
Dec 28, 2012 at 6:39pm
FMatrix has no resize capability, so you can not expect it to resize with your vector.

The simple solution is to make a new FMatrix whenever needed.

As to get the constant int:
const int sizeX = myFirstVector.size();
Last edited on Dec 28, 2012 at 6:40pm
Dec 28, 2012 at 9:09pm
I do make a new FMatrix whenever i create a new vector writing :

const int sizeX = myFirstVector.size();

But when it compiles it doesn't know the size of the vector (whitch is calculate during the execution) so he can't create the FMatrix and send an error message.

I'll try to find the explicite library. Thanks for your time
Dec 28, 2012 at 9:15pm
Last edited on Dec 28, 2012 at 9:17pm
Dec 29, 2012 at 12:39am
But when it compiles it doesn't know the size of the vector (whitch is calculate during the execution) so he can't create the FMatrix and send an error message.


Then perhaps use pointers and new?
Topic archived. No new replies allowed.