How could I make a constructor that accepts a templated number of floats?

Code:`template<int N>`

class vector

{

vector(float _1, ..., float _N); // ???

};

Printable View

- 05-15-2011User Name:Implement an N deminsional mathematical vector.
How could I make a constructor that accepts a templated number of floats?

Code:`template<int N>`

class vector

{

vector(float _1, ..., float _N); // ???

};

- 05-15-2011User Name:
I'm using C++0x, btw,

- 05-15-2011tabstop
To be honest, this sounds more like a job for ... then for templates.

- 05-15-2011User Name:
Is it possible to limit the number of arguments with ...?

- 05-15-2011tabstop
- 05-15-2011User Name:
I realize there is a limit to the size of the stack. :)

How would you define an N dimensional vector? - 05-15-2011tabstop
Really depends on the context of what I'm using these for. Since you wrote "mathematical vector" I'm assuming you're looking for something you want to be able to do operations like + and * on. Since you can't ever really operate with two different sizes at the same time, I don't know that I'd worry about making them compatible unless you have to make a bunch of different sizes.

- 05-15-2011User Name:
That's a good idea. I was planning on only allowing N vectors to be used with N vectors, it was just the generalization of the math that I was after. I'll still use the template, but leave it absract and specialize the ones I actually plan to use.

Like so:

Code:`template<int N>`

class vector

{

public:

vector(...) = 0;

};

template<>

class vector<3>

{

public:

vector(float, float, float)

{

}

vector<3> operator+(const vector<3>&){}

};

- 05-16-2011Elysia
For taking a variable argument list, you might use std::initializer_list if it's supported.