I was looking at "How to properly use references with variadic templates," and wondered how far comma expansion can go.
Here's a variant of the answer:
inline void inc() { }
template<typename T,typename ...Args>
inline void inc(T& t, Args& ...args) { ++t; inc(args...); }
Since variadic arguments are expanded to a comma-separated list of their elements, are those commas semantically equivalent to template/function-argument separators, or are they inserted lexically, making them suitable for any (post-preprocessor) use, including the comma operator?
This works on my GCC-4.6:
// Use the same zero-argument "inc"
template<typename T,typename ...Args>
inline void inc(T& t, Args& ...args) { ++t, inc(args...); }
But when I tried:
// Use the same zero-argument "inc"
template<typename T,typename ...Args>
inline void inc(T& t, Args& ...args) { ++t, ++args...; }
I kept getting parsing errors, expecting the ";" before the "...", and that "args" won't get its pack expanded. Why doesn't it work? Is it because if "args" is empty, we get an invalid blob of punctuation? Is it legal, and my compiler isn't good enough?
(I've tried surrounding "args" in parentheses, and/or use post-increment; neither worked.)