How can I pull variadic template arguments off from the tail instead of the head?

Viewed 2727

For silly reasons I'll not go into here, I need the commented out line to work and the line above it it to not work:

template<uint _N, typename... _Args>
struct PartialTuple;

template<uint _N, typename _Arg, typename... _Args>
struct PartialTuple<_N, _Arg, _Args...>: PartialTuple<_N-1, _Args...> {};

template<typename _Arg, typename... _Args>
struct PartialTuple<0, _Arg, _Args...>
{
    typedef std::tuple<_Arg, _Args...> type;
};

int main()
{
    // I want this to not work...
    PartialTuple<1, std::string, std::string, int, int>::type A{"test", 5, 1};

    // I want this to work...
    //PartialTuple<1, std::string, std::string, int, int>::type B{"test", "test", 5};
}

I tried swapping _Arg with _Args..., but that won't compile (at least in GCC 4.6):

error: parameter pack argument ‘_Args ...’ must be at the end of the template argument list

How can I pull items off from the tail instead of from the head?

4 Answers
Related