Variable parameter templates
Variable-parameter templates to create template functions and template classes that can accept variable quantities of parameters
This program uses template functions to instantiate the basic usage of variable parameter templates
#include <iostream>
using namespace Std;
void One () {}//requires a non-parametric overloaded version when the last parameter is passed
Template <typename t>//When the last argument is left, the compiler takes precedence over the template so that the last output has no comma behind it.
void One (T v)
{
cout << v << Endl;
}
//... As a meta operator
F is a template parameter package, F is a function parameter package, T is matched with a type, F differs from T in that F matches any number of types
The key point is that the template parameter package F is matched to the function parameter package F, both in type and quantity.
Template <typename T, TypeName ... F>
void One (T V, f ... f)//each time a pass is taken out of all parameters to give V, so that you can recursively complete all the arguments
{
cout << v << ",";
One (f ...); The meta-operator ... On the right side of F, you can expand the parameter pack and expand a series of parameters passed to F
}
int main ()
{
One ("ASD", 1,2,3,4); This series of parameters is passed to the template function package f,f and then the parameter packet is passed to the function parameter package F
return 0;
}
Variable parameter template usage