I have an std::tuple
and I want to split it at an arbitrary compile-time parameter N
. I have seen solutions floating around for getting the head and the tail of an std::tuple
like here , here or here , but these cannot solve my problem since for me this constant (like 1) that is being passed as a template argument is a runtime parameter and that defeats the purpose of an std::index_sequence
. For example something like this, doesn't work:
#include <iostream>
#include <tuple>
#include <utility>
template < typename T , typename... Ts >
auto head( std::tuple<T,Ts...> t )
{
return std::get<0>(t);
}
template <std::size_t... Ns , typename... Ts>
auto tail_impl( std::index_sequence<Ns...> , std::tuple<Ts...> t, std::size_t N)
{
return std::make_tuple( std::get<Ns + N>(t)... );
}
template < std::size_t N, typename... Ts>
auto tail( std::tuple<Ts...> t)
{
return tail_impl( std::make_index_sequence<sizeof...(Ts) - N>() , t, N);
}
int main()
{
auto t = std::make_tuple( 2, 3.14 , 'c' , 5);
std::cout << std::get<0>( tail<2>(t) ) << std::endl;
}
Therefore my question is: Is this possible? This would be simpler if I could have an std::index_sequence
starting from an arbitrary N
for example but I couldn't find how to do that.