|
1745 | 1745 |
|
1746 | 1746 | \item In a \tcode{sizeof...} expression~(\ref{expr.sizeof}); the pattern is an |
1747 | 1747 | \grammarterm{identifier}. |
| 1748 | + |
| 1749 | +\item In a \grammarterm{fold-expression} (\ref{expr.prim.fold}); |
| 1750 | +the pattern is the \grammarterm{cast-expression} |
| 1751 | +that contains an unexpanded parameter pack. |
1748 | 1752 | \end{itemize} |
1749 | 1753 |
|
1750 | 1754 | \pnum |
|
1804 | 1808 |
|
1805 | 1809 | \pnum |
1806 | 1810 | The instantiation of a pack expansion |
1807 | | -that is not a \tcode{sizeof...} expression |
| 1811 | +that is neither a \tcode{sizeof...} expression |
| 1812 | +nor a \grammarterm{fold-expression} |
1808 | 1813 | produces a |
1809 | 1814 | list |
1810 | 1815 | $\mathtt{E}_1, \mathtt{E}_2, ..., \mathtt{E}_N$, |
|
1855 | 1860 | an integral constant containing the number of elements in the parameter pack |
1856 | 1861 | it expands. |
1857 | 1862 |
|
| 1863 | +\pnum |
| 1864 | +The instantiation of a \grammarterm{fold-expression} produces: |
| 1865 | + |
| 1866 | +\begin{itemize} |
| 1867 | +\item |
| 1868 | +\tcode{((}$\mathtt{E}_1$ |
| 1869 | + \placeholder{op} $\mathtt{E}_2$\tcode{)} |
| 1870 | + \placeholder{op} $\cdots$\tcode{)} |
| 1871 | + \placeholder{op} $\mathtt{E}_N$ |
| 1872 | +for a unary left fold, |
| 1873 | +\item |
| 1874 | + $\mathtt{E}_1$ \placeholder{op} |
| 1875 | +\tcode{(}$\cdots$ \placeholder{op} |
| 1876 | +\tcode{(}$\mathtt{E}_{N-1}$ \placeholder{op} |
| 1877 | + $\mathtt{E}_N$\tcode{))} |
| 1878 | +for a unary right fold, |
| 1879 | +\item |
| 1880 | +\tcode{(((}$\mathtt{E}$ |
| 1881 | + \placeholder{op} $\mathtt{E}_1$\tcode{)} |
| 1882 | + \placeholder{op} $\mathtt{E}_2$\tcode{)} |
| 1883 | + \placeholder{op} $\cdots$\tcode{)} |
| 1884 | + \placeholder{op} $\mathtt{E}_N$ |
| 1885 | +for a binary left fold, and |
| 1886 | +\item |
| 1887 | + $\mathtt{E}_1$ \placeholder{op} |
| 1888 | +\tcode{(}$\cdots$ \placeholder{op} |
| 1889 | +\tcode{(}$\mathtt{E}_{N-1}$ \placeholder{op} |
| 1890 | +\tcode{(}$\mathtt{E}_{N}$ \placeholder{op} |
| 1891 | + $\mathtt{E}$\tcode{)))} |
| 1892 | +for a binary right fold. |
| 1893 | +\end{itemize} |
| 1894 | + |
| 1895 | +In each case, |
| 1896 | +\placeholder{op} is the \grammarterm{fold-operator}, |
| 1897 | +$N$ is the number of elements in the pack expansion parameters, |
| 1898 | +and each $\mathtt{E}_i$ is generated by instantiating the pattern |
| 1899 | +and replacing each pack expansion parameter with its $i$th element. |
| 1900 | +For a binary fold-expression, |
| 1901 | +$\mathtt{E}$ is generated |
| 1902 | +by instantiating the \grammarterm{cast-expression} |
| 1903 | +that did not contain an unexpanded parameter pack. |
| 1904 | +\enterexample |
| 1905 | +\begin{codeblock} |
| 1906 | +template<typename ...Args> |
| 1907 | + bool all(Args ...args) { return (... && args); } |
| 1908 | + |
| 1909 | +bool b = all(true, true, true, false); |
| 1910 | +\end{codeblock} |
| 1911 | +Within the instantiation of \tcode{all}, |
| 1912 | +the returned expression expands to |
| 1913 | +\tcode{((true \&\& true) \&\& true) \&\& false}, |
| 1914 | +which evalutes to \tcode{false}. |
| 1915 | +\exitexample |
| 1916 | +If $N$ is zero for a unary fold-expression, |
| 1917 | +the value of the expression is shown in Table~\ref{tab:fold.empty}; |
| 1918 | +if the operator is not listed in Table~\ref{tab:fold.empty}, |
| 1919 | +the instantiation is ill-formed. |
| 1920 | + |
| 1921 | +\begin{floattable}{Value of folding empty sequences}{tab:fold.empty} |
| 1922 | +{ll} |
| 1923 | +\topline |
| 1924 | +\lhdr{Operator} & \rhdr{Value when parameter pack is empty} \\ |
| 1925 | +\capsep |
| 1926 | +\tcode{*} & \tcode{1} \\ |
| 1927 | +\tcode{+} & \tcode{int()} \\ |
| 1928 | +\tcode{\&} & \tcode{-1} \\ |
| 1929 | +\tcode{|} & \tcode{int()} \\ |
| 1930 | +\tcode{\&\&} & \tcode{true} \\ |
| 1931 | +\tcode{||} & \tcode{false} \\ |
| 1932 | +\tcode{,} & \tcode{void()} \\ |
| 1933 | +\end{floattable} |
| 1934 | + |
1858 | 1935 | \rSec2[temp.friend]{Friends} |
1859 | 1936 |
|
1860 | 1937 | \pnum |
|
3954 | 4031 | A \grammarterm{braced-init-list} is type-dependent if any element is |
3955 | 4032 | type-dependent or is a pack expansion. |
3956 | 4033 |
|
| 4034 | +\pnum |
| 4035 | +A \grammarterm{fold-expression} is type-dependent. |
| 4036 | + |
3957 | 4037 | \rSec3[temp.dep.constexpr]{Value-dependent expressions} |
3958 | 4038 |
|
3959 | 4039 | \pnum |
|
4024 | 4104 | Expressions of the following form are value-dependent: |
4025 | 4105 |
|
4026 | 4106 | \begin{ncbnftab} |
4027 | | -\terminal{sizeof} \terminal{...} \terminal{(} identifier \terminal{)} |
| 4107 | +\terminal{sizeof} \terminal{...} \terminal{(} identifier \terminal{)}\br |
| 4108 | +fold-expression |
4028 | 4109 | \end{ncbnftab} |
4029 | 4110 |
|
4030 | 4111 | \pnum |
|
0 commit comments