|
2800 | 2800 | \end{example}
|
2801 | 2801 |
|
2802 | 2802 | \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$, |
2809 | 2805 | 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 |
2812 | 2808 | replacing each pack expansion parameter with its $i^\text{th}$ element.
|
2813 | 2809 | Such an element, in the context of the instantiation, is interpreted as
|
2814 | 2810 | follows:
|
2815 | 2811 | \begin{itemize}
|
2816 | 2812 | \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; |
2821 | 2822 |
|
2822 | 2823 | \item
|
2823 | 2824 | if the pack is a function parameter pack, the element is an
|
|
2835 | 2836 | that resulted from instantiation of
|
2836 | 2837 | the \grammarterm{init-capture} pack.
|
2837 | 2838 | \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 |
2849 | 2842 | 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 | 2843 |
|
2862 | 2844 | \pnum
|
2863 | 2845 | 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$. |
2866 | 2847 |
|
2867 | 2848 | \pnum
|
2868 |
| -The instantiation of a \grammarterm{fold-expression} produces: |
| 2849 | +The instantiation of a \grammarterm{fold-expression}\iref{expr.prim.fold} produces: |
2869 | 2850 | \begin{itemize}
|
2870 | 2851 | \item
|
2871 | 2852 | \tcode{((}$\mathtt{E}_1$
|
|
2896 | 2877 | \end{itemize}
|
2897 | 2878 |
|
2898 | 2879 | 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, |
2904 | 2882 | $\mathtt{E}$ is generated
|
2905 | 2883 | by instantiating the \grammarterm{cast-expression}
|
2906 | 2884 | that did not contain an unexpanded pack.
|
|
2916 | 2894 | \tcode{((true \&\& true) \&\& true) \&\& false},
|
2917 | 2895 | which evaluates to \tcode{false}.
|
2918 | 2896 | \end{example}
|
2919 |
| -If $N$ is zero for a unary fold-expression, |
| 2897 | +If $N$ is zero for a unary fold, |
2920 | 2898 | the value of the expression is shown in \tref{temp.fold.empty};
|
2921 | 2899 | if the operator is not listed in \tref{temp.fold.empty},
|
2922 | 2900 | the instantiation is ill-formed.
|
|
2931 | 2909 | \tcode{,} & \tcode{void()} \\
|
2932 | 2910 | \end{floattable}
|
2933 | 2911 |
|
| 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 | + |
2934 | 2934 | \rSec2[temp.friend]{Friends}
|
2935 | 2935 |
|
2936 | 2936 | \pnum
|
|
0 commit comments