Possible Duplicate:
Convert std::tuple to std::array C++11
Suppose you have:
template<class T,int N>
struct A {
A(const B& b): /* what comes here */ {}
std::array<T,N> F;
};
I need each element of F[] to be constructed with the argument of the constructor, in above case b. This is tricky because the argument might not be of a type that can be a compile-time constant, like int etc.
This is different to Is it possible to construct the elements of a member array depending on an integral template parameter? since here a user-defined struct is used and thus we need run-time copies of it.
The indices trick can be applied here too, you just need to transform it a bit:
Live example.
We basically ignore the values of the indices and only use the pack itself to perform the expansion, i.e. only the size of the pack is of interest to us. Reusing indices for this might seem like abuse, since we’re not interested in the actual values, but I think reusing the machinery here is fine. Any other construct to create an
N-element pack would look the same, except that the pack would most likely just contain zeros.