diff --git a/source/templates.tex b/source/templates.tex index 9afde74251..deb9caca89 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -2800,24 +2800,25 @@ \end{example} \pnum -The instantiation of a pack expansion -that is neither a \tcode{sizeof...} expression -nor a \grammarterm{fold-expression} -produces a -list of elements -$\mathtt{E}_1,$ $\mathtt{E}_2,$ $\cdots,$ $\mathtt{E}_N$, +The instantiation of a pack expansion considers +items $\tcode{E}_1, \tcode{E}_2, \dotsc, \tcode{E}_N$, where -$N$ is the number of elements in the pack expansion parameters. Each -$\mathtt{E}_i$ is generated by instantiating the pattern and +$N$ is the number of elements in the pack expansion parameters. +Each $\tcode{E}_i$ is generated by instantiating the pattern and replacing each pack expansion parameter with its $i^\text{th}$ element. Such an element, in the context of the instantiation, is interpreted as follows: \begin{itemize} \item -if the pack is a template parameter pack, the element is a template -parameter\iref{temp.param} of the corresponding kind (type or -non-type) designating the $i^\text{th}$ -corresponding type or value template argument; +if the pack is a template parameter pack, the element is +an \grammarterm{id-expression} +(for a non-type template parameter pack), +a \grammarterm{typedef-name} +(for a type template parameter pack declared without \tcode{template}), or +a \grammarterm{template-name} +(for a type template parameter pack declared with \tcode{template}) +if the pack was introduced by a pack expansion, +designating the $i^\text{th}$ corresponding type or value template argument; \item if the pack is a function parameter pack, the element is an @@ -2835,37 +2836,17 @@ that resulted from instantiation of the \grammarterm{init-capture} pack. \end{itemize} - -All of the $\mathtt{E}_i$ become items in the enclosing list. -\begin{note} -The variety of list varies with the context: -\grammarterm{expression-list}, -\grammarterm{base-specifier-list}, -\grammarterm{template-argument-list}, etc. -\end{note} -When $N$ is zero, the instantiation of the expansion produces an empty list. -Such an instantiation does not alter the syntactic interpretation of the -enclosing construct, even in cases where omitting the list entirely would +When $N$ is zero, the instantiation of a pack expansion +does not alter the syntactic interpretation of the enclosing construct, +even in cases where omitting the pack expansion entirely would otherwise be ill-formed or would result in an ambiguity in the grammar. -\begin{example} -\begin{codeblock} -template struct X : T... { }; -template void f(T... values) { - X x(values...); -} - -template void f<>(); // OK: \tcode{X<>} has no base classes - // \tcode{x} is a variable of type \tcode{X<>} that is value-initialized -\end{codeblock} -\end{example} \pnum The instantiation of a \tcode{sizeof...} expression\iref{expr.sizeof} produces -an integral constant containing the number of elements in the pack -it expands. +an integral constant with value $N$. \pnum -The instantiation of a \grammarterm{fold-expression} produces: +The instantiation of a \grammarterm{fold-expression}\iref{expr.prim.fold} produces: \begin{itemize} \item \tcode{((}$\mathtt{E}_1$ @@ -2896,11 +2877,8 @@ \end{itemize} In each case, -\placeholder{op} is the \grammarterm{fold-operator}, -$N$ is the number of elements in the pack expansion parameters, -and each $\mathtt{E}_i$ is generated by instantiating the pattern -and replacing each pack expansion parameter with its $i^\text{th}$ element. -For a binary fold-expression, +\placeholder{op} is the \grammarterm{fold-operator}. +For a binary fold, $\mathtt{E}$ is generated by instantiating the \grammarterm{cast-expression} that did not contain an unexpanded pack. @@ -2916,7 +2894,7 @@ \tcode{((true \&\& true) \&\& true) \&\& false}, which evaluates to \tcode{false}. \end{example} -If $N$ is zero for a unary fold-expression, +If $N$ is zero for a unary fold, the value of the expression is shown in \tref{temp.fold.empty}; if the operator is not listed in \tref{temp.fold.empty}, the instantiation is ill-formed. @@ -2931,6 +2909,28 @@ \tcode{,} & \tcode{void()} \\ \end{floattable} +\pnum +The instantiation of any other pack expansion +produces a list of elements $\tcode{E}_1, \tcode{E}_2, \dotsc, \tcode{E}_N$. +\begin{note} +The variety of list varies with the context: +\grammarterm{expression-list}, +\grammarterm{base-specifier-list}, +\grammarterm{template-argument-list}, etc. +\end{note} +When $N$ is zero, the instantiation of the expansion produces an empty list. +\begin{example} +\begin{codeblock} +template struct X : T... { }; +template void f(T... values) { + X x(values...); +} + +template void f<>(); // OK: \tcode{X<>} has no base classes + // \tcode{x} is a variable of type \tcode{X<>} that is value-initialized +\end{codeblock} +\end{example} + \rSec2[temp.friend]{Friends} \pnum