可变模板参数函数
1.逗号表达式展开参数包
template<class F, typename... Args>
void expand(const F& f, Args... args)
{
initializer_list<int>{(f(std::forward< Args>(args)), 0)...};
}
//expand([](auto i){cout << i << endl; }, 1, 2.0, ”test”);
2.递归函数方式展开
template <class T>
void printarg(T&& t)
{
std::cout << t << std::endl;
}
//终止递归
template<typename T>
void processValues(T &&arg)
{
printarg(std::forward<T>(arg));
}
template<typename T, typename... Ts>
void processValues(T &&arg, Ts&& ...args)
{
printarg(std::forward<T>(arg));
processValues(std::forward<Ts>(args)...);
}
可变模板参数类
1.模版偏特化和递归方式来展开参数包
//前向声明
template<typename... Args>
struct sum;
//基本定义
templ