ZhangXiongpang
ZhangXiongpang

Reputation: 278

A confusion about variadic templates in c++11 standard

What is the difference between the two functions?

template <class ...Types> void f(Types... args...){}
template <class ...Types> void g(Types... args){}

Upvotes: 2

Views: 169

Answers (1)

Xeo
Xeo

Reputation: 131887

f is exactly the same as

template <class ...Types> void f(Types... args, ...){}
//                                            ^^^^^

I.e., it's just a plain old variadic parameter list from C. For historical reasons, it can be used without the usual , that is needed to seperate parameters. The difference to g is exactly that parameter.

Note that no arguments will ever be passed to the C-style variadic parameter list, since the C++-style variadic parameters will "swallow" all arguments.

Upvotes: 7

Related Questions