|
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 $\mathtt{E}_1,$ $\mathtt{E}_2,$ $\cdots,$ $\mathtt{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 $\mathtt{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:
|
|
2836 | 2832 | the \grammarterm{init-capture} pack.
|
2837 | 2833 | \end{itemize}
|
2838 | 2834 |
|
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 |
| - |
2862 | 2835 | \pnum
|
2863 | 2836 | 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$. |
2866 | 2838 |
|
2867 | 2839 | \pnum
|
2868 |
| -The instantiation of a \grammarterm{fold-expression} produces: |
| 2840 | +The instantiation of a \grammarterm{fold-expression}\iref{expr.prim.fold} produces: |
2869 | 2841 | \begin{itemize}
|
2870 | 2842 | \item
|
2871 | 2843 | \tcode{((}$\mathtt{E}_1$
|
|
2896 | 2868 | \end{itemize}
|
2897 | 2869 |
|
2898 | 2870 | 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, |
2904 | 2873 | $\mathtt{E}$ is generated
|
2905 | 2874 | by instantiating the \grammarterm{cast-expression}
|
2906 | 2875 | that did not contain an unexpanded pack.
|
|
2916 | 2885 | \tcode{((true \&\& true) \&\& true) \&\& false},
|
2917 | 2886 | which evaluates to \tcode{false}.
|
2918 | 2887 | \end{example}
|
2919 |
| -If $N$ is zero for a unary fold-expression, |
| 2888 | +If $N$ is zero for a unary fold, |
2920 | 2889 | the value of the expression is shown in \tref{temp.fold.empty};
|
2921 | 2890 | if the operator is not listed in \tref{temp.fold.empty},
|
2922 | 2891 | the instantiation is ill-formed.
|
|
2931 | 2900 | \tcode{,} & \tcode{void()} \\
|
2932 | 2901 | \end{floattable}
|
2933 | 2902 |
|
| 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 | + |
2934 | 2929 | \rSec2[temp.friend]{Friends}
|
2935 | 2930 |
|
2936 | 2931 | \pnum
|
|
0 commit comments