Is it possible to go from `std::array` to `parameter pack` or `variadic`?

Hi guys
Quick question that I hope you guys would know the answer to..
Is it possible to go from `std::array` to `parameter pack` or `variadic`?
More precisely, consider this scenario as an example of what I’m asking
 
template <typename T, N>
T builtT() {
std::array<complexclass, N> array;

// ... populate array with some awesome login ...

return {array...}; <-- This
}
You already invited:

Eston

Upvotes from:

yes

you just need to build an index sequence
it's the same as working with a tuple, basically
although tbh it's a bit rare to go from array to parameter pack
because all the types are the same. So you're going from something that's easy to work with but more constrained, to something less constrained and harder to work with.

plante

Upvotes from:

template <typename T, std::size_t N, std::size ... Is>
T buildT_helper(std::index_sequence<Is...>) {
std::array<complexclass, N> array;
...
return {array[Is]...};
}

template <typename T, std::size_t N>
T buildT() { return buildT_helper(std::make_index_sequence<N>{}); }
 
 
Seems like maybe it would be simpler to just give `T` a constructor taking an array?

if you control T
but, I don't have broader context obviously... so if you want to stick with how you're doing it, the code above should help

If you wanna answer this question please Login or Register