I have the following constructor:
class A {
template<class ...T>
A(std::initializer_list<T> && ... args);
}
And I have the code for that class:
A a1 = {{5.0f, 6.0f}, {-7.0f, 8.0f}};
A a2 = {{{5.0f, 3.f}, {6.0f, 7.f}}, {{-7.0f, 9.f}, {12.f, 8.0f}}};
a1
can be compiled and a2
can't be compiled. I understand, curly braces are only syntax sugar and not making the type by default, only when passing it to function with arguments that can be initilized with initilizer_list (e.g. std::initializer_list<float>
in case of A
and variable a1
).
I wonder, is there any workaround that can help passing any dimensional std::initializer_list<std::initializer_list<std::initializer_list<...>...>...>
to function/constructor?
I checked documentation and tried several different hacks but it will not work.
So, basic answer would be it is not possible.
It is not possible to make constructor or any other function accepting brace list of undefined number of brace lists because brace list has no type and cannot be implicitly converted to std::initilizer_list<...>
.