2

I get confused when I encounter this sentence (bold) from the standard - [temp.deduct]/11:

[ Note: Type deduction may fail for the following reasons:

  • (11.1) Attempting to instantiate a pack expansion containing multiple packs of differing lengths.
  • [..]

It's known that "instantiation" is a process of creating an instance of a class or template. So a pack expansion is not a template or class to instantiate an instance from.

My question is what does "instantiating a pack expansion" mean? Is it mean "expanding" pack expansion?

And how I can instantiate a pack expansion?

Evg
  • 25,259
  • 5
  • 41
  • 83
mada
  • 1,646
  • 1
  • 15
  • 1
    Try reading it, in context, using the meaning "instantiating a template whose body contains a pack expansion". But the latter "multiple packs of different lengths" must be inside a single expansion, when the containing template is instantiated, and not merely in a template containing multiple independent expansions. – Ben Voigt Aug 08 '22 at 18:22
  • 1
    @BenVoigt - It is referred also to in [temp.variadic]/5: _"A pack expansion consists of a pattern and an ellipsis, **the instantiation of which** produces zero or more instantiations of the pattern in a list [...] "_ – mada Aug 08 '22 at 18:41
  • @BenVoigt - ...and in [temp.variadic]/8: "_**The instantiation of a pack expansion** considers items [...]_" – mada Aug 08 '22 at 18:43
  • It's just the principle that instantiating a thing (template) that has a body structure containing many smaller things (statements, expressions, pack expansions) you end up with an instance of every component inside the body structure. So you might say all those components of the body have also been instantiated. – Ben Voigt Aug 08 '22 at 20:11
  • https://timsong-cpp.github.io/cppwp/n4861/temp.param#18 defines pack expansion in another context – Yakk - Adam Nevraumont Aug 08 '22 at 21:44
  • @John https://timsong-cpp.github.io/cppwp/n4861/temp.variadic#8 link for your quote – Yakk - Adam Nevraumont Aug 08 '22 at 21:46
  • @BenVoigt - "_Try reading it, in context, using the meaning "instantiating a template whose body contains a pack expansion"._" - Interesting. Suppose you have a function template `g` takes two type parameters, and you have the following: `template auto f() -> decltype((g(), ...)); ` Then your wording is not applied: the pack expansion is in the function type of `f` not in its body. – mada Aug 09 '22 at 05:53
  • @BenVoigt - So if I take your rule as "instantiating a pack expansion" means "_instantiating a template whose body or function type (since pack expansion cannot appear as a default argument of another pack) contains a pack expansion_", this would still be correct? – mada Aug 09 '22 at 06:09

0 Answers0