Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My compiler allows "T&...". Is this an extension?

I was surprised when the following worked

template<typename T>
void f(T &...);

I thought that I have to declare "T" as "typename ...T" then, and that it only works in C++0x. But the above compiled in strict C++03 mode. What's going on?

like image 943
Johannes Schaub - litb Avatar asked Feb 05 '11 16:02

Johannes Schaub - litb


2 Answers

It's just the bad old C varargs syntax; the grammar allows omitting the comma. The following are equivalent:

int printf(const char* fmt, ...);
int printf(const char* fmt...);
like image 170
JohannesD Avatar answered Sep 30 '22 03:09

JohannesD


Did you call the function? Template functions don't get compiled until you call them. And in Visual Studio 2010, IntelliSense shows the real syntax of that function would be

template <class T> void f(T&, ...)

Smells like old variable argument syntax.

like image 40
Xeo Avatar answered Sep 30 '22 04:09

Xeo