This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ PATCH: PR 20599 (variadic templates, take two) (1/4)

Doug Gregor wrote:
PACK_UNPACK_*'s can actually be used to "pack" arguments during
template argument deduction. For instance, with tuple and its partial

template<typename... Args> struct tuple;

 template<typename Head, typename... Tail>
   struct tuple<Head, Tail...> { };

When we're doing template argument deduction for "tuple<int, float,
double>", we essentially "pack" float and double into the template
parameter pack "Tail". But, when we're expanding that type
"tuple<Head, Tail...>" given bindings for Head and Tail, we're
unpacking "Tail". At parse time we don't know whether we'll be using
the expression to pack (template argument deduction), unpack
(instantiation), or both. Even if we did know, the same
CLASSTYPE_TI_ARGS for tuple<Head, Tail...> will be used for both
template argument deduction and later instantiation.

Right. Perhaps thinking about packing and unpacking with that tree code is the wrong level of granularity. The PACK_UNPACK_* code just deals with the substitution, creating a new pack based on the argument packs. It's the context in which it's used that actually does the unpacking, right? "Tail..." just represents a pack.

Also, the definition seem to allow for using multiple packs in a single
expansion, but the proposal doesn't cover that.

It's in the proposal, but it's not stressed enough. The examples with rvalue references (section 2.4, bottom of page 5) show expansion with multiple parameter packs ("Args" is a template type parameter pack, "args" is a function parameter pack).

Ah, I see. And if that happens we assume that all the packs have the same number of elements?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]