I would like to be able to initialize my objects with a brace-init-list:
#include <initializer_list>
template <class T>
struct S {
T v[5];
S(std::initializer_list<T> l) {
int ind = 0;
for (auto &&i: l){
v[ind] = i;
ind++;
}
}
};
int main()
{
S<int> s = {1, 2, 3, 4, 5};
}
As I found out here: https://en.cppreference.com/w/cpp/utility/initializer_list, it is necessary to use the standard library for this.
But that is strange for me. I would suggest that such initialization is a part of the C++ syntax.
Is it possible to create a constructor without use of std:initializer_list
?
Edit:
It could be useful for programming embedding devices where standard library is not available (e.g. Arduino AVR).