Reputation: 24739
The old C stdio facilities provided a way to pass along a variadic argument set using the vprintf
facilities.
Is there a similar way to pass along a C++0x variadic template parameter pack without expanding it?
This might be useful if you have a derived class constructor that takes a variadic template parameter pack, and needs to simply pass it on to the base class constructor, rather than unpacking it.
For example:
template <class T, class... Args>
Base::Base(const T& v, const Args&... args)
{
/*...expand args here ....*/
}
template <class T, class... Args>
Derived::Derived(const T& v, const Args&... args) : Base(v, args)
{
/*...don't expand args...*/
}
I thought you could simply pass around the args
parameter pack without expanding it, by excluding the ...
after the args, but this simply results in a compiler error on GCC 4.3:
error: parameter packs not expanded with `...'
So it is possible to pass along the parameter pack without expanding it?
Upvotes: 4
Views: 4627
Reputation: 76835
I don't understand how expanding is an issue : won't expanded arguments be just re-packed in Base constructor ? I believe using args...
will work as expected.
Upvotes: 7