I'm trying to implement a flexible constructor for my struct Polynomial :
struct Polynomial
{
std::vector<float> coefficients;
size_t degree;
};
The degree of the polynomial is variable. What I would like is to have a constructor like
Polynomial(float... _coefficients);
I've tried variadic template :
template<float... Args>
Polynomial(Args... args);
But float is a non-type, so I've done :
template<typename... Args>
Polynomial(Args... args);
But this allow my coefficients to be anything, not realy what I want. I know I could use :
Polynomial(size_t _degree, ...);
But it is really unsafe.
At the moment I'm using :
Polynomial(std::vector<float>);
But this force the call to be like :
Polynomial P({f1, f2, f3}); // with fn floats
So I would like to know if there is a good way to do this.
Thank you !