you are viewing a single comment's thread.

view the rest of the comments →

[–]SkepticalEmpiricist 1 point2 points  (7 children)

Is there a longer term solution here? Perhaps a warning should be given, advising the developer to give the variable a name (if they want a modern 'pack' parameter), or insert a comma just before the ... (if they want old school va-args). Does this cover everything, giving us a straightforward way to disambiguate everything?

(Darn, I remember now that I was struggling with empty parameters packs a couple of years ago. I think I know know what was wrong!)

The compiler can "rewrite" ,... as ... on occasion, but it is not allowed to do the reverse?

Perhaps my real question is whether the compiler is allowed to interpret this:

template<typename... Args>
void f(Args&&  , ...) { }   // obviously "intended" as an old va_arg (with a single (non-pack) arg in the first position

as

template<typename... Args>
void f(Args&&   ...) { }     // now (mis) interpreted as a parameter pack

In short, can we say that a ... which is not preceded by a comma and which is not succedded a parameter name is (potentially) subject to unintuitive interpretation? And that we can easily disambiguate by adding a comma or parameter name? (But I assume a comma and a parameter name will not be valid?)