tubberd
tubberd

Reputation: 540

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.

Upvotes: 5

Views: 1272

Answers (1)

Jarod42
Jarod42

Reputation: 217398

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

Upvotes: 11

Related Questions