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
How could I make a constructor that accepts a templated number of floats?
Code:template<int N>
class vector
{
vector(float _1, ..., float _N); // ???
};
I'm using C++0x, btw,
To be honest, this sounds more like a job for ... then for templates.
Is it possible to limit the number of arguments with ...?
I realize there is a limit to the size of the stack. :)
How would you define an N dimensional vector?
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.
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:
Thanks for your time and help.Code:template<int N>
class vector
{
public:
vector(...) = 0;
};
template<>
class vector<3>
{
public:
vector(float, float, float)
{
}
vector<3> operator+(const vector<3>&){}
};
For taking a variable argument list, you might use std::initializer_list if it's supported.