Skip to content

Commit 1e889e0

Browse files
authored
[temp.variadic] Rearrange description of pack expansion (#4543)
1 parent b6e0848 commit 1e889e0

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

source/templates.tex

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,24 +2800,25 @@
28002800
\end{example}
28012801

28022802
\pnum
2803-
The instantiation of a pack expansion
2804-
that is neither a \tcode{sizeof...} expression
2805-
nor a \grammarterm{fold-expression}
2806-
produces a
2807-
list of elements
2808-
$\mathtt{E}_1,$ $\mathtt{E}_2,$ $\cdots,$ $\mathtt{E}_N$,
2803+
The instantiation of a pack expansion considers
2804+
items $\tcode{E}_1, \tcode{E}_2, \dotsc, \tcode{E}_N$,
28092805
where
2810-
$N$ is the number of elements in the pack expansion parameters. Each
2811-
$\mathtt{E}_i$ is generated by instantiating the pattern and
2806+
$N$ is the number of elements in the pack expansion parameters.
2807+
Each $\tcode{E}_i$ is generated by instantiating the pattern and
28122808
replacing each pack expansion parameter with its $i^\text{th}$ element.
28132809
Such an element, in the context of the instantiation, is interpreted as
28142810
follows:
28152811
\begin{itemize}
28162812
\item
2817-
if the pack is a template parameter pack, the element is a template
2818-
parameter\iref{temp.param} of the corresponding kind (type or
2819-
non-type) designating the $i^\text{th}$
2820-
corresponding type or value template argument;
2813+
if the pack is a template parameter pack, the element is
2814+
an \grammarterm{id-expression}
2815+
(for a non-type template parameter pack),
2816+
a \grammarterm{typedef-name}
2817+
(for a type template parameter pack declared without \tcode{template}), or
2818+
a \grammarterm{template-name}
2819+
(for a type template parameter pack declared with \tcode{template})
2820+
if the pack was introduced by a pack expansion,
2821+
designating the $i^\text{th}$ corresponding type or value template argument;
28212822

28222823
\item
28232824
if the pack is a function parameter pack, the element is an
@@ -2835,37 +2836,17 @@
28352836
that resulted from instantiation of
28362837
the \grammarterm{init-capture} pack.
28372838
\end{itemize}
2838-
2839-
All of the $\mathtt{E}_i$ become items in the enclosing list.
2840-
\begin{note}
2841-
The variety of list varies with the context:
2842-
\grammarterm{expression-list},
2843-
\grammarterm{base-specifier-list},
2844-
\grammarterm{template-argument-list}, etc.
2845-
\end{note}
2846-
When $N$ is zero, the instantiation of the expansion produces an empty list.
2847-
Such an instantiation does not alter the syntactic interpretation of the
2848-
enclosing construct, even in cases where omitting the list entirely would
2839+
When $N$ is zero, the instantiation of a pack expansion
2840+
does not alter the syntactic interpretation of the enclosing construct,
2841+
even in cases where omitting the pack expansion entirely would
28492842
otherwise be ill-formed or would result in an ambiguity in the grammar.
2850-
\begin{example}
2851-
\begin{codeblock}
2852-
template<class... T> struct X : T... { };
2853-
template<class... T> void f(T... values) {
2854-
X<T...> x(values...);
2855-
}
2856-
2857-
template void f<>(); // OK: \tcode{X<>} has no base classes
2858-
// \tcode{x} is a variable of type \tcode{X<>} that is value-initialized
2859-
\end{codeblock}
2860-
\end{example}
28612843

28622844
\pnum
28632845
The instantiation of a \tcode{sizeof...} expression\iref{expr.sizeof} produces
2864-
an integral constant containing the number of elements in the pack
2865-
it expands.
2846+
an integral constant with value $N$.
28662847

28672848
\pnum
2868-
The instantiation of a \grammarterm{fold-expression} produces:
2849+
The instantiation of a \grammarterm{fold-expression}\iref{expr.prim.fold} produces:
28692850
\begin{itemize}
28702851
\item
28712852
\tcode{((}$\mathtt{E}_1$
@@ -2896,11 +2877,8 @@
28962877
\end{itemize}
28972878

28982879
In each case,
2899-
\placeholder{op} is the \grammarterm{fold-operator},
2900-
$N$ is the number of elements in the pack expansion parameters,
2901-
and each $\mathtt{E}_i$ is generated by instantiating the pattern
2902-
and replacing each pack expansion parameter with its $i^\text{th}$ element.
2903-
For a binary fold-expression,
2880+
\placeholder{op} is the \grammarterm{fold-operator}.
2881+
For a binary fold,
29042882
$\mathtt{E}$ is generated
29052883
by instantiating the \grammarterm{cast-expression}
29062884
that did not contain an unexpanded pack.
@@ -2916,7 +2894,7 @@
29162894
\tcode{((true \&\& true) \&\& true) \&\& false},
29172895
which evaluates to \tcode{false}.
29182896
\end{example}
2919-
If $N$ is zero for a unary fold-expression,
2897+
If $N$ is zero for a unary fold,
29202898
the value of the expression is shown in \tref{temp.fold.empty};
29212899
if the operator is not listed in \tref{temp.fold.empty},
29222900
the instantiation is ill-formed.
@@ -2931,6 +2909,28 @@
29312909
\tcode{,} & \tcode{void()} \\
29322910
\end{floattable}
29332911

2912+
\pnum
2913+
The instantiation of any other pack expansion
2914+
produces a list of elements $\tcode{E}_1, \tcode{E}_2, \dotsc, \tcode{E}_N$.
2915+
\begin{note}
2916+
The variety of list varies with the context:
2917+
\grammarterm{expression-list},
2918+
\grammarterm{base-specifier-list},
2919+
\grammarterm{template-argument-list}, etc.
2920+
\end{note}
2921+
When $N$ is zero, the instantiation of the expansion produces an empty list.
2922+
\begin{example}
2923+
\begin{codeblock}
2924+
template<class... T> struct X : T... { };
2925+
template<class... T> void f(T... values) {
2926+
X<T...> x(values...);
2927+
}
2928+
2929+
template void f<>(); // OK: \tcode{X<>} has no base classes
2930+
// \tcode{x} is a variable of type \tcode{X<>} that is value-initialized
2931+
\end{codeblock}
2932+
\end{example}
2933+
29342934
\rSec2[temp.friend]{Friends}
29352935

29362936
\pnum

0 commit comments

Comments
 (0)