Reputation: 2911
Is there a way to std::forward a specific range of arguments in a variadic function? For example:
#include <iostream>
template<typename T>
void test_simple(T v0,T v1)
{
std::cout<<v0<<","<<v1<<std::endl;
}
template<typename... TARGS>
void test_variadic(TARGS ...args)
{
test_simple(std::forward<TARGS>(args)...); // Forward all arguments except for the first one?
}
int main(int argc,char *argv[])
{
test_variadic(5.f,2.f,7.f);
return EXIT_SUCCESS;
}
I want test_variadic to forward only the last two arguments to test_simple, so that the output would be "2.0,7.0".
Upvotes: 2
Views: 214
Reputation: 48938
Use an additional template parameter:
template <typename T, typename... Ts>
void test_variadic(T&& arg, Ts&&... args) {
test_simple(std::forward<Ts>(args)...);
}
That way, the first parameter is not part of the variadic.
Upvotes: 5