Skip to content

Commit 521d60a

Browse files
committed
[temp.variadic] Rearrange description of pack expansion
1 parent c071212 commit 521d60a

File tree

1 file changed

+35
-40
lines changed

1 file changed

+35
-40
lines changed

source/templates.tex

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,15 +2800,11 @@
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:
@@ -2836,36 +2832,12 @@
28362832
the \grammarterm{init-capture} pack.
28372833
\end{itemize}
28382834

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
2849-
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}
2861-
28622835
\pnum
28632836
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.
2837+
an integral constant with value $N$.
28662838

28672839
\pnum
2868-
The instantiation of a \grammarterm{fold-expression} produces:
2840+
The instantiation of a \grammarterm{fold-expression}\iref{expr.prim.fold} produces:
28692841
\begin{itemize}
28702842
\item
28712843
\tcode{((}$\mathtt{E}_1$
@@ -2896,11 +2868,8 @@
28962868
\end{itemize}
28972869

28982870
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,
2871+
\placeholder{op} is the \grammarterm{fold-operator}.
2872+
For a binary fold,
29042873
$\mathtt{E}$ is generated
29052874
by instantiating the \grammarterm{cast-expression}
29062875
that did not contain an unexpanded pack.
@@ -2916,7 +2885,7 @@
29162885
\tcode{((true \&\& true) \&\& true) \&\& false},
29172886
which evaluates to \tcode{false}.
29182887
\end{example}
2919-
If $N$ is zero for a unary fold-expression,
2888+
If $N$ is zero for a unary fold,
29202889
the value of the expression is shown in \tref{temp.fold.empty};
29212890
if the operator is not listed in \tref{temp.fold.empty},
29222891
the instantiation is ill-formed.
@@ -2931,6 +2900,32 @@
29312900
\tcode{,} & \tcode{void()} \\
29322901
\end{floattable}
29332902

2903+
\pnum
2904+
The instantiation of any other pack expansion
2905+
produces a list of elements
2906+
$\mathtt{E}_1,$ $\mathtt{E}_2,$ $\cdots,$ $\mathtt{E}_N$.
2907+
\begin{note}
2908+
The variety of list varies with the context:
2909+
\grammarterm{expression-list},
2910+
\grammarterm{base-specifier-list},
2911+
\grammarterm{template-argument-list}, etc.
2912+
\end{note}
2913+
When $N$ is zero, the instantiation of the expansion produces an empty list.
2914+
Such an instantiation does not alter the syntactic interpretation of the
2915+
enclosing construct, even in cases where omitting the list entirely would
2916+
otherwise be ill-formed or would result in an ambiguity in the grammar.
2917+
\begin{example}
2918+
\begin{codeblock}
2919+
template<class... T> struct X : T... { };
2920+
template<class... T> void f(T... values) {
2921+
X<T...> x(values...);
2922+
}
2923+
2924+
template void f<>(); // OK: \tcode{X<>} has no base classes
2925+
// \tcode{x} is a variable of type \tcode{X<>} that is value-initialized
2926+
\end{codeblock}
2927+
\end{example}
2928+
29342929
\rSec2[temp.friend]{Friends}
29352930

29362931
\pnum

0 commit comments

Comments
 (0)