# Thread: Implement an N deminsional mathematical vector.

1. ## 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); // ???
};```

2. I'm using C++0x, btw,

3. To be honest, this sounds more like a job for ... then for templates.

4. Is it possible to limit the number of arguments with ...?

5. Originally Posted by User Name:
Is it possible to limit the number of arguments with ...?
There's probably an internal limit of something outrageous like 16384, but I don't know of a way to limit it otherwise. (Flip side: same would be true of your template solution if it existed.)

6. I realize there is a limit to the size of the stack.

How would you define an N dimensional vector?

7. 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.

8. 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>&){}
};```
Thanks for your time and help.

9. For taking a variable argument list, you might use std::initializer_list if it's supported.