Vahagn Vahagn - 22 days ago 5
C++ Question

How to obtain a template parameter pack of integers int a function?

Say I want to have a function like:

void reset()
{
(std::get</*pack of integers from 0 to 4*/>(someTuple).reset(), ...);
}


I did it with a helper function like this:

template < size_t... Indexes >
void reset(std::integer_sequence<size_t, Indexes...>)
{
(std::get<Indexes>(someTuple).reset(), ...);
}
void reset()
{
reset(std::make_integer_sequence<size_t,5>{});
}


But can I achieve this with just one function? The attempt like:

template < size_t... Indexes >
void reset(std::integer_sequence<size_t, Indexes...> = std::make_integer_sequence<size_t,5>{})
{
(std::get<Indexes>(someTuple).reset(), ...);
}


failed as the call
reset()
resolved to
reset<>(std::integer_sequence<size_t>)
rather than to
reset<0,1,2,3,4>(std::integer_sequence<size_t,0,1,2,3,4>)
. I am using the latest snapshot of GCC-7.0.0

Answer

As @Ryan Haining said in the comment, what i wrote in the question is the best way to go.