Skip to content

Commit 2e1c196

Browse files
committed
[temp.variadic] Rearrange description of pack expansion
1 parent aa08a75 commit 2e1c196

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed

source/templates.tex

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,24 +2800,26 @@
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 $\mathtt{E}_1,$ $\mathtt{E}_2,$ $\cdots,$ $\mathtt{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 $\mathtt{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+
designating the $i^\text{th}$ template parameter
2821+
that resulted from instantiation of
2822+
the template parameter pack.
28212823

28222824
\item
28232825
if the pack is a function parameter pack, the element is an
@@ -2835,37 +2837,17 @@
28352837
that resulted from instantiation of
28362838
the \grammarterm{init-capture} pack.
28372839
\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
2840+
When $N$ is zero, the instantiation of a pack expansion
2841+
does not alter the syntactic interpretation of the enclosing construct,
2842+
even in cases where omitting the pack expansion entirely would
28492843
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}
28612844

28622845
\pnum
28632846
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.
2847+
an integral constant with value $N$.
28662848

28672849
\pnum
2868-
The instantiation of a \grammarterm{fold-expression} produces:
2850+
The instantiation of a \grammarterm{fold-expression}\iref{expr.prim.fold} produces:
28692851
\begin{itemize}
28702852
\item
28712853
\tcode{((}$\mathtt{E}_1$
@@ -2896,11 +2878,8 @@
28962878
\end{itemize}
28972879

28982880
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,
2881+
\placeholder{op} is the \grammarterm{fold-operator}.
2882+
For a binary fold,
29042883
$\mathtt{E}$ is generated
29052884
by instantiating the \grammarterm{cast-expression}
29062885
that did not contain an unexpanded pack.
@@ -2916,7 +2895,7 @@
29162895
\tcode{((true \&\& true) \&\& true) \&\& false},
29172896
which evaluates to \tcode{false}.
29182897
\end{example}
2919-
If $N$ is zero for a unary fold-expression,
2898+
If $N$ is zero for a unary fold,
29202899
the value of the expression is shown in \tref{temp.fold.empty};
29212900
if the operator is not listed in \tref{temp.fold.empty},
29222901
the instantiation is ill-formed.
@@ -2931,6 +2910,29 @@
29312910
\tcode{,} & \tcode{void()} \\
29322911
\end{floattable}
29332912

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

29362938
\pnum

0 commit comments

Comments
 (0)