How to transform types from variadic template parameters to another type?
For example:
template <typename... T>
struct single
{
std::tuple<T...> m_single;
};
template <typename... T>
struct sequences
{
single<T...> get(size_t pos)
{
// I don't know how to convert here
return std::make_tuple(std::get<0>(m_sequences)[pos]... std::get<N>(m_sequences)[pos]);
}
template <size_t Idx>
std::vector<
typename std::tuple_element<Idx, std::tuple<T...>>::type
>
get_sequence()
{
return std::get<Idx>(m_sequences);
}
std::tuple<T...> m_sequences; // std::tuple<std::vector<T...>> I don't know how to conver here
};
I want to write so:
sequences<int, double, double> seq;
single<int, double, double> sin = seq.get(10);
And have std::tuple<std::vector<int>, std::vector<double>, std::vector<double>>
in struct sequences. And get single from it.
std::vector<single<T...>>
is bad idea for me, because i need get one sequence full to and it's easy to copy it from .
Is it possible?
Thank you very much. Sorry for my bad English.
You can do more than just expand a variadic parameter pack as a plain list: you can expand an expression too. You can therefore have
m_sequences
be a tuple of vectors rather than a tuple of the elements:You can also do nifty tricks with parameter packs to pick the appropriate element from the vector:
OK, this might seem a bit like overkill but how about this: As far as I know the only option to "iterate" variadics is using the
<head, tail...>
notation with a template specialization for the simple<head-only>
case.Therefore you could try something like this:
simple case:
recursive case:
Disclaimer: not tested, not even compiled, but I suppose you get the basic idea. At least two problems remain:
get()
is not your single struct but a tuple chain. Perhaps you can unchain it recursively withstd::get<0>
...V
can differ fromT
.