#include <iostream>
template<class ... Ts>
void f(Ts ... args)
{
const int size = sizeof...(args) + 1;
int res[size] = {1, args...};
std::cout << "------" << std::endl;
for (int i = 1; i < size; i++)
{
std::cout << res[i] << std::endl;
}
}
int main()
{
f();
f(1);
f(1, 2);
f(1, 2, 3);
return 0;
}
/* Output:
------
------
1
------
1
2
------
1
2
3
*******/
References: https://isocpp.org/wiki/faq/cpp11-language-templates#variadic-templateshttp://en.cppreference.com/w/cpp/language/parameter_pack
No comments:
Post a Comment