The argument template that appears in c++11 lets us not care about the parameters of the function call, similar to implementing the printf function in C.
The arguments depend on the powerful templates of C + +
Can declare this
Template<class T1,class ... Args>//args is a type parameter package that requires recursive parsing in defined functions
void Mutiarg (const T1&t1,args ... Args)
{
Do something with T1 operation on the first invocation parameter
Mutiarg (args ...); The parameter packet is recursively parsed, and the function is called until its number of arguments is 1 o'clock stop call
}
Call the function below when the number of arguments is resolved to only one
Template<class t1>
void Mutiarg (const T1&T1)
{
Do something with T1
}
A complete example of testing directly below
#incldue <iostream>
#include <string>
Template<class T1, class ... Args>
void Mutiarg (const t1&t1, args ... args)
{
Std::cout << T1 << Std::endl;
Mutiarg (args ...);
}
Template<class t>
void Mutiarg (const t& T)
{
Std::cout << "t=" << t << Std::endl;
Std::cout << "End" << Std::endl;
}
void Main ()
{
Mutiarg (1,1.2,3, "string", ' C ');
}
The result of the operation is
1
1.2
3
String
C
--------------End
c++11 template for variable parameters