C++11's six dots


Posted by Louis Brandy on 18 February 2013

I was mucking around the other day and discovered this nice little oddity:

template <typename... Args>
void foo(Args......);

As it turns out, ...... can be totally valid C++11. This is what happens when backward compatibility mixes with new hotness.

// These are all equivalent.

template <typename... Args> void foo1(Args......);
template <typename... Args> void foo2(Args... ...);
template <typename... Args> void foo3(Args..., ...);

Hopefully the last one shows what is happening here. This is two ellipsis operators, one for varadiac templates, and the second for old C-style varargs. Needless to say, I really hope you never need to use this, but if you do, I really hope you’ve carefully exhausted all other options.

I really wanted to end this post with an example of something at least believably useful, but that was almost impossible.


← i'm back! C++11 variadic templates, for the doubters. →


© louis brandy — theme: midnight by mattgraham — with help from jekyll bootstrap and github pages