I'm trying to write a container class for vector arithmetic. The objects are static in size:
template<typename T, unsigned N>
class vec{
T data[N] = {0};
public:
vec(std::initializer_list<T> ini){
std::copy(ini.begin(), ini.end(), data);
}
}
This is how far I got.
But than I tested the std::array class for comparison and I noticed that it somehow could make a static assertion if the initializer list was to long or to short.
std::array<float, 2> a = {1, 2, 3, 4} <- instant error message from the visual studio ide
In my class I would have to check the length of the initializer list at run-time.
I assume, that the std::array class somehow manages it to directly initialize the data with the initializer list notation without the std::initializer_list class.
Is it possible to initialize my class in the same way as std::array?