【发布时间】:2018-09-07 06:55:59
【问题描述】:
有没有办法std::forward 可变参数函数中的特定范围的参数?例如:
#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;
}
我希望 test_variadic 只将最后两个参数转发给 test_simple,这样输出就会是“2.0,7.0”。
【问题讨论】:
-
你想删除第一个参数,还是转发 2 last? (与 3 个参数相同,但与其他数字不同)。
标签: c++ variadic-templates variadic-functions variadic