Get first N elements of parameter pack

c++, c++14, variadic-templates

Solution

This is a slight variation on @skypjack's answer that avoids using tuples:

template <size_t... N_i,size_t... M_i>
auto foo2(std::index_sequence<M_i...>)
{
    constexpr size_t values[] = {N_i...};
    return A<values[M_i]...>();
}

template <size_t N,size_t... N_i>
auto foo()
{
    return foo2<N_i...>(std::make_index_sequence<N>());
}

Problem

I have to following problem: ``` template< size_t... N_i > class A { // ... }; template< size_t N, size_t... N_i > A</* first N elements of N_i...*/> foo() { A</* first N elements of N_i...*/> a; // ... return a; } int main() { A<1,2> res = foo<2, 1,2,3,4>(); return 0; } ``` Here, I want `foo` to have the return type `A</* first N size_t of N_i...*/>`, i.e., the `class A` which has as template arguments the first N elements of the parameter pack `N_i`. Does anyone know how this can be implemented?

Original source