I am trying to pass multiple initializer lists through a variadic template to construct an std::array in place.
However I fail to find a version that compiles (C++17).
Consider the following code:
struct TwoInts {
TwoInts(int x, int y)
: a{x}
, b{y}
{}
int a,b;
};
template<typename T, int S>
struct Holder {
template<typename... Args>
Holder(Args&&... args) : m({{std::forward<Args>(args)...}}) {}
//Deleted for clarity of the example:
Holder(const Holder& o) = delete;
Holder(Holder&& o) = delete;
std::array<T,S> m;
};
We can perform the following initializations:
TwoInts a = {1,2};
std::array<TwoInts,1> b{{{1,2}}};
std::array<TwoInts,2> c{{{1,2},{3,4}}};
Holder<int,1> d{1};
Holder<int,2> e{1,2};
But how to modify the example to make this work?
Holder<TwoInts,1> f{{{1,2}}};
Holder<TwoInts,2> f{{{1,2},{3,4}}};
Gcc and clang fail find a matching constructor.