C++ 在一个变量函数中前进一个特定的参数范围
有没有一种方法可以在变量函数中转发特定范围的参数?例如:C++ 在一个变量函数中前进一个特定的参数范围,c++,variadic-templates,variadic-functions,variadic,C++,Variadic Templates,Variadic Functions,Variadic,有没有一种方法可以在变量函数中转发特定范围的参数?例如: #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 ...a
#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;
}
#包括
模板
无效试验(T v0,T v1)
{
std::cout使用额外的模板参数:
template <typename T, typename... Ts>
void test_variadic(T&& arg, Ts&&... args) {
test_simple(std::forward<Ts>(args)...);
}
模板
无效测试变量(T&&arg,Ts&&args){
简单测试(标准:正向(args)…);
}
这样一来,第一个参数就不是变量的一部分。您是要删除第一个参数,还是要转发2个lasts?(与3个参数相同,但与其他数字不同)。