|
1881 | 1881 |
|
1882 | 1882 | \item In a \tcode{sizeof...} expression~(\ref{expr.sizeof}); the pattern is an |
1883 | 1883 | \grammarterm{identifier}. |
| 1884 | + |
| 1885 | +\item In a \grammarterm{fold-expression} (\ref{expr.prim.fold}); |
| 1886 | +the pattern is the \grammarterm{cast-expression} |
| 1887 | +that contains an unexpanded parameter pack. |
1884 | 1888 | \end{itemize} |
1885 | 1889 |
|
1886 | 1890 | \pnum |
|
1940 | 1944 |
|
1941 | 1945 | \pnum |
1942 | 1946 | The instantiation of a pack expansion |
1943 | | -that is not a \tcode{sizeof...} expression |
| 1947 | +that is neither a \tcode{sizeof...} expression |
| 1948 | +nor a \grammarterm{fold-expression} |
1944 | 1949 | produces a |
1945 | 1950 | list |
1946 | 1951 | $\mathtt{E}_1, \mathtt{E}_2, ..., \mathtt{E}_N$, |
|
1991 | 1996 | an integral constant containing the number of elements in the parameter pack |
1992 | 1997 | it expands. |
1993 | 1998 |
|
| 1999 | +\pnum |
| 2000 | +The instantiation of a \grammarterm{fold-expression} produces: |
| 2001 | + |
| 2002 | +\begin{itemize} |
| 2003 | +\item |
| 2004 | +\tcode{((}$\mathtt{E}_1$ |
| 2005 | + \placeholder{op} $\mathtt{E}_2$\tcode{)} |
| 2006 | + \placeholder{op} $\cdots$\tcode{)} |
| 2007 | + \placeholder{op} $\mathtt{E}_N$ |
| 2008 | +for a unary left fold, |
| 2009 | +\item |
| 2010 | + $\mathtt{E}_1$ \placeholder{op} |
| 2011 | +\tcode{(}$\cdots$ \placeholder{op} |
| 2012 | +\tcode{(}$\mathtt{E}_{N-1}$ \placeholder{op} |
| 2013 | + $\mathtt{E}_N$\tcode{))} |
| 2014 | +for a unary right fold, |
| 2015 | +\item |
| 2016 | +\tcode{(((}$\mathtt{E}$ |
| 2017 | + \placeholder{op} $\mathtt{E}_1$\tcode{)} |
| 2018 | + \placeholder{op} $\mathtt{E}_2$\tcode{)} |
| 2019 | + \placeholder{op} $\cdots$\tcode{)} |
| 2020 | + \placeholder{op} $\mathtt{E}_N$ |
| 2021 | +for a binary left fold, and |
| 2022 | +\item |
| 2023 | + $\mathtt{E}_1$ \placeholder{op} |
| 2024 | +\tcode{(}$\cdots$ \placeholder{op} |
| 2025 | +\tcode{(}$\mathtt{E}_{N-1}$ \placeholder{op} |
| 2026 | +\tcode{(}$\mathtt{E}_{N}$ \placeholder{op} |
| 2027 | + $\mathtt{E}$\tcode{)))} |
| 2028 | +for a binary right fold. |
| 2029 | +\end{itemize} |
| 2030 | + |
| 2031 | +In each case, |
| 2032 | +\placeholder{op} is the \grammarterm{fold-operator}, |
| 2033 | +$N$ is the number of elements in the pack expansion parameters, |
| 2034 | +and each $\mathtt{E}_i$ is generated by instantiating the pattern |
| 2035 | +and replacing each pack expansion parameter with its $i$th element. |
| 2036 | +For a binary fold-expression, |
| 2037 | +$\mathtt{E}$ is generated |
| 2038 | +by instantiating the \grammarterm{cast-expression} |
| 2039 | +that did not contain an unexpanded parameter pack. |
| 2040 | +\enterexample |
| 2041 | +\begin{codeblock} |
| 2042 | +template<typename ...Args> |
| 2043 | + bool all(Args ...args) { return (... && args); } |
| 2044 | + |
| 2045 | +bool b = all(true, true, true, false); |
| 2046 | +\end{codeblock} |
| 2047 | +Within the instantiation of \tcode{all}, |
| 2048 | +the returned expression expands to |
| 2049 | +\tcode{((true \&\& true) \&\& true) \&\& false}, |
| 2050 | +which evalutes to \tcode{false}. |
| 2051 | +\exitexample |
| 2052 | +If $N$ is zero for a unary fold-expression, |
| 2053 | +the value of the expression is shown in Table~\ref{tab:fold.empty}; |
| 2054 | +if the operator is not listed in Table~\ref{tab:fold.empty}, |
| 2055 | +the instantiation is ill-formed. |
| 2056 | + |
| 2057 | +\begin{floattable}{Value of folding empty sequences}{tab:fold.empty} |
| 2058 | +{ll} |
| 2059 | +\topline |
| 2060 | +\lhdr{Operator} & \rhdr{Value when parameter pack is empty} \\ |
| 2061 | +\capsep |
| 2062 | +\tcode{*} & \tcode{1} \\ |
| 2063 | +\tcode{+} & \tcode{int()} \\ |
| 2064 | +\tcode{\&} & \tcode{-1} \\ |
| 2065 | +\tcode{|} & \tcode{int()} \\ |
| 2066 | +\tcode{\&\&} & \tcode{true} \\ |
| 2067 | +\tcode{||} & \tcode{false} \\ |
| 2068 | +\tcode{,} & \tcode{void()} \\ |
| 2069 | +\end{floattable} |
| 2070 | + |
1994 | 2071 | \rSec2[temp.friend]{Friends} |
1995 | 2072 |
|
1996 | 2073 | \pnum |
|
4002 | 4079 | is the type of the class member access expression. |
4003 | 4080 | \exitnote |
4004 | 4081 |
|
| 4082 | +\pnum |
| 4083 | +A \grammarterm{fold-expression} is type-dependent. |
| 4084 | + |
4005 | 4085 | \rSec3[temp.dep.constexpr]{Value-dependent expressions} |
4006 | 4086 |
|
4007 | 4087 | \pnum |
|
4072 | 4152 | Expressions of the following form are value-dependent: |
4073 | 4153 |
|
4074 | 4154 | \begin{ncbnftab} |
4075 | | -\terminal{sizeof} \terminal{...} \terminal{(} identifier \terminal{)} |
| 4155 | +\terminal{sizeof} \terminal{...} \terminal{(} identifier \terminal{)}\br |
| 4156 | +fold-expression |
4076 | 4157 | \end{ncbnftab} |
4077 | 4158 |
|
4078 | 4159 | \pnum |
|
0 commit comments