Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Offset for variadic template integer sequence

Ok, i'll try to keep this short. I know you can generate an integer sequence for variadic templates with std::index_sequence_for. Now suppose i want that index sequence to start at a specific offset, but still be the same length as the variadic template argument list. Is that possible? I didn't find anything of the sort on cppreference.

like image 652
tubberd Avatar asked Dec 25 '22 08:12

tubberd


1 Answers

You may write your own easily:

template <std::size_t Offset, std::size_t ... Is>
std::index_sequence<(Offset + Is)...> add_offset(std::index_sequence<Is...>)
{
    return {};
}

template <std::size_t Offset, std::size_t N>
auto make_index_sequence_with_offset()
{
    return add_offset<Offset>(std::make_index_sequence<N>{});
}

Demo

like image 148
Jarod42 Avatar answered Dec 28 '22 10:12

Jarod42