tmp/tmpuqmcsnjw/{from.md → to.md}
RENAMED
|
@@ -49,15 +49,33 @@ foo(); // xs contains zero init-captures
|
|
| 49 |
foo(1); // xs contains one init-capture
|
| 50 |
```
|
| 51 |
|
| 52 |
— *end example*]
|
| 53 |
|
| 54 |
-
A *pack* is
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
A *pack expansion* consists of a *pattern* and an ellipsis, the
|
| 61 |
instantiation of which produces zero or more instantiations of the
|
| 62 |
pattern in a list (described below). The form of the pattern depends on
|
| 63 |
the context in which the expansion occurs. Pack expansions can occur in
|
|
@@ -65,15 +83,21 @@ the following contexts:
|
|
| 65 |
|
| 66 |
- In a function parameter pack [[dcl.fct]]; the pattern is the
|
| 67 |
*parameter-declaration* without the ellipsis.
|
| 68 |
- In a *using-declaration* [[namespace.udecl]]; the pattern is a
|
| 69 |
*using-declarator*.
|
|
|
|
|
|
|
| 70 |
- In a template parameter pack that is a pack expansion [[temp.param]]:
|
| 71 |
- if the template parameter pack is a *parameter-declaration*; the
|
| 72 |
pattern is the *parameter-declaration* without the ellipsis;
|
| 73 |
- if the template parameter pack is a *type-parameter*; the pattern is
|
| 74 |
-
the corresponding *type-parameter* without the ellipsis
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
- In an *initializer-list* [[dcl.init]]; the pattern is an
|
| 76 |
*initializer-clause*.
|
| 77 |
- In a *base-specifier-list* [[class.derived]]; the pattern is a
|
| 78 |
*base-specifier*.
|
| 79 |
- In a *mem-initializer-list* [[class.base.init]] for a
|
|
@@ -81,20 +105,26 @@ the following contexts:
|
|
| 81 |
pattern is the *mem-initializer*.
|
| 82 |
- In a *template-argument-list* [[temp.arg]]; the pattern is a
|
| 83 |
*template-argument*.
|
| 84 |
- In an *attribute-list* [[dcl.attr.grammar]]; the pattern is an
|
| 85 |
*attribute*.
|
|
|
|
|
|
|
| 86 |
- In an *alignment-specifier* [[dcl.align]]; the pattern is the
|
| 87 |
*alignment-specifier* without the ellipsis.
|
| 88 |
- In a *capture-list* [[expr.prim.lambda.capture]]; the pattern is the
|
| 89 |
*capture* without the ellipsis.
|
| 90 |
- In a `sizeof...` expression [[expr.sizeof]]; the pattern is an
|
| 91 |
*identifier*.
|
|
|
|
|
|
|
| 92 |
- In a *fold-expression* [[expr.prim.fold]]; the pattern is the
|
| 93 |
*cast-expression* that contains an unexpanded pack.
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
[*Example
|
| 96 |
|
| 97 |
``` cpp
|
| 98 |
template<class ... Types> void f(Types ... rest);
|
| 99 |
template<class ... Types> void g(Types ... rest) {
|
| 100 |
f(&rest ...); // ``&rest ...'' is a pack expansion; ``&rest'' is its pattern
|
|
@@ -114,11 +144,11 @@ a pack expansion shall name one or more packs that are not expanded by a
|
|
| 114 |
nested pack expansion; such packs are called *unexpanded packs* in the
|
| 115 |
pattern. All of the packs expanded by a pack expansion shall have the
|
| 116 |
same number of arguments specified. An appearance of a name of a pack
|
| 117 |
that is not expanded is ill-formed.
|
| 118 |
|
| 119 |
-
[*Example
|
| 120 |
|
| 121 |
``` cpp
|
| 122 |
template<typename...> struct Tuple {};
|
| 123 |
template<typename T1, typename T2> struct Pair {};
|
| 124 |
|
|
@@ -150,33 +180,45 @@ The instantiation of a pack expansion considers items
|
|
| 150 |
expansion parameters. Each `Eᵢ` is generated by instantiating the
|
| 151 |
pattern and replacing each pack expansion parameter with its iᵗʰ
|
| 152 |
element. Such an element, in the context of the instantiation, is
|
| 153 |
interpreted as follows:
|
| 154 |
|
| 155 |
-
- if the pack is a template parameter pack, the element is
|
| 156 |
-
*
|
| 157 |
-
*
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
| 161 |
- if the pack is a function parameter pack, the element is an
|
| 162 |
*id-expression* designating the iᵗʰ function parameter that resulted
|
| 163 |
from instantiation of the function parameter pack declaration;
|
| 164 |
-
otherwise
|
| 165 |
- if the pack is an *init-capture* pack, the element is an
|
| 166 |
*id-expression* designating the variable introduced by the iᵗʰ
|
| 167 |
*init-capture* that resulted from instantiation of the *init-capture*
|
| 168 |
-
pack declaration
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
When N is zero, the instantiation of a pack expansion does not alter the
|
| 171 |
syntactic interpretation of the enclosing construct, even in cases where
|
| 172 |
omitting the pack expansion entirely would otherwise be ill-formed or
|
| 173 |
would result in an ambiguity in the grammar.
|
| 174 |
|
| 175 |
The instantiation of a `sizeof...` expression [[expr.sizeof]] produces
|
| 176 |
an integral constant with value N.
|
| 177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
The instantiation of a *fold-expression* [[expr.prim.fold]] produces:
|
| 179 |
|
| 180 |
- `(` `((`E₁ *op* E₂`)` *op* ⋯`)` *op* $\mathtt{E}_N$ `)` for a unary
|
| 181 |
left fold,
|
| 182 |
- `(` E₁ *op* `(`⋯ *op* `(`$\mathtt{E}_{N-1}$ *op* $\mathtt{E}_N$`))`
|
|
@@ -188,11 +230,11 @@ The instantiation of a *fold-expression* [[expr.prim.fold]] produces:
|
|
| 188 |
|
| 189 |
In each case, *op* is the *fold-operator*. For a binary fold, E is
|
| 190 |
generated by instantiating the *cast-expression* that did not contain an
|
| 191 |
unexpanded pack.
|
| 192 |
|
| 193 |
-
[*Example
|
| 194 |
|
| 195 |
``` cpp
|
| 196 |
template<typename ...Args>
|
| 197 |
bool all(Args ...args) { return (... && args); }
|
| 198 |
|
|
@@ -215,21 +257,23 @@ If N is zero for a unary fold, the value of the expression is shown in
|
|
| 215 |
| `&&` | `true` |
|
| 216 |
| `||` | `false` |
|
| 217 |
| `,` | `void()` |
|
| 218 |
|
| 219 |
|
|
|
|
|
|
|
| 220 |
The instantiation of any other pack expansion produces a list of
|
| 221 |
elements `E₁`, `E₂`, …, `E_N`.
|
| 222 |
|
| 223 |
[*Note 1*: The variety of list varies with the context:
|
| 224 |
*expression-list*, *base-specifier-list*, *template-argument-list*,
|
| 225 |
etc. — *end note*]
|
| 226 |
|
| 227 |
When N is zero, the instantiation of the expansion produces an empty
|
| 228 |
list.
|
| 229 |
|
| 230 |
-
[*Example
|
| 231 |
|
| 232 |
``` cpp
|
| 233 |
template<class... T> struct X : T... { };
|
| 234 |
template<class... T> void f(T... values) {
|
| 235 |
X<T...> x(values...);
|
|
|
|
| 49 |
foo(1); // xs contains one init-capture
|
| 50 |
```
|
| 51 |
|
| 52 |
— *end example*]
|
| 53 |
|
| 54 |
+
A *structured binding pack* is an *sb-identifier* that introduces zero
|
| 55 |
+
or more structured bindings [[dcl.struct.bind]].
|
| 56 |
+
|
| 57 |
+
[*Example 4*:
|
| 58 |
+
|
| 59 |
+
``` cpp
|
| 60 |
+
auto foo() -> int(&)[2];
|
| 61 |
+
|
| 62 |
+
template <class T>
|
| 63 |
+
void g() {
|
| 64 |
+
auto [...a] = foo(); // a is a structured binding pack containing two elements
|
| 65 |
+
auto [b, c, ...d] = foo(); // d is a structured binding pack containing zero elements
|
| 66 |
+
}
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
— *end example*]
|
| 70 |
+
|
| 71 |
+
A *pack* is a template parameter pack, a function parameter pack, an
|
| 72 |
+
*init-capture* pack, or a structured binding pack. The number of
|
| 73 |
+
elements of a template parameter pack or a function parameter pack is
|
| 74 |
+
the number of arguments provided for the parameter pack. The number of
|
| 75 |
+
elements of an *init-capture* pack is the number of elements in the pack
|
| 76 |
+
expansion of its *initializer*.
|
| 77 |
|
| 78 |
A *pack expansion* consists of a *pattern* and an ellipsis, the
|
| 79 |
instantiation of which produces zero or more instantiations of the
|
| 80 |
pattern in a list (described below). The form of the pattern depends on
|
| 81 |
the context in which the expansion occurs. Pack expansions can occur in
|
|
|
|
| 83 |
|
| 84 |
- In a function parameter pack [[dcl.fct]]; the pattern is the
|
| 85 |
*parameter-declaration* without the ellipsis.
|
| 86 |
- In a *using-declaration* [[namespace.udecl]]; the pattern is a
|
| 87 |
*using-declarator*.
|
| 88 |
+
- In a *friend-type-declaration* [[class.mem.general]]; the pattern is a
|
| 89 |
+
*friend-type-specifier*.
|
| 90 |
- In a template parameter pack that is a pack expansion [[temp.param]]:
|
| 91 |
- if the template parameter pack is a *parameter-declaration*; the
|
| 92 |
pattern is the *parameter-declaration* without the ellipsis;
|
| 93 |
- if the template parameter pack is a *type-parameter*; the pattern is
|
| 94 |
+
the corresponding *type-parameter* without the ellipsis;
|
| 95 |
+
- if the template parameter pack is a template template parameter; the
|
| 96 |
+
pattern is the corresponding *type-tt-parameter*,
|
| 97 |
+
*variable-tt-parameter*, or *concept-tt-parameter* without the
|
| 98 |
+
ellipsis.
|
| 99 |
- In an *initializer-list* [[dcl.init]]; the pattern is an
|
| 100 |
*initializer-clause*.
|
| 101 |
- In a *base-specifier-list* [[class.derived]]; the pattern is a
|
| 102 |
*base-specifier*.
|
| 103 |
- In a *mem-initializer-list* [[class.base.init]] for a
|
|
|
|
| 105 |
pattern is the *mem-initializer*.
|
| 106 |
- In a *template-argument-list* [[temp.arg]]; the pattern is a
|
| 107 |
*template-argument*.
|
| 108 |
- In an *attribute-list* [[dcl.attr.grammar]]; the pattern is an
|
| 109 |
*attribute*.
|
| 110 |
+
- In an *annotation-list* [[dcl.attr.grammar]]; the pattern is an
|
| 111 |
+
*annotation*.
|
| 112 |
- In an *alignment-specifier* [[dcl.align]]; the pattern is the
|
| 113 |
*alignment-specifier* without the ellipsis.
|
| 114 |
- In a *capture-list* [[expr.prim.lambda.capture]]; the pattern is the
|
| 115 |
*capture* without the ellipsis.
|
| 116 |
- In a `sizeof...` expression [[expr.sizeof]]; the pattern is an
|
| 117 |
*identifier*.
|
| 118 |
+
- In a *pack-index-expression*; the pattern is an *identifier*.
|
| 119 |
+
- In a *pack-index-specifier*; the pattern is a *typedef-name*.
|
| 120 |
- In a *fold-expression* [[expr.prim.fold]]; the pattern is the
|
| 121 |
*cast-expression* that contains an unexpanded pack.
|
| 122 |
+
- In a fold expanded constraint [[temp.constr.fold]]; the pattern is the
|
| 123 |
+
constraint of that fold expanded constraint.
|
| 124 |
|
| 125 |
+
[*Example 5*:
|
| 126 |
|
| 127 |
``` cpp
|
| 128 |
template<class ... Types> void f(Types ... rest);
|
| 129 |
template<class ... Types> void g(Types ... rest) {
|
| 130 |
f(&rest ...); // ``&rest ...'' is a pack expansion; ``&rest'' is its pattern
|
|
|
|
| 144 |
nested pack expansion; such packs are called *unexpanded packs* in the
|
| 145 |
pattern. All of the packs expanded by a pack expansion shall have the
|
| 146 |
same number of arguments specified. An appearance of a name of a pack
|
| 147 |
that is not expanded is ill-formed.
|
| 148 |
|
| 149 |
+
[*Example 6*:
|
| 150 |
|
| 151 |
``` cpp
|
| 152 |
template<typename...> struct Tuple {};
|
| 153 |
template<typename T1, typename T2> struct Pair {};
|
| 154 |
|
|
|
|
| 180 |
expansion parameters. Each `Eᵢ` is generated by instantiating the
|
| 181 |
pattern and replacing each pack expansion parameter with its iᵗʰ
|
| 182 |
element. Such an element, in the context of the instantiation, is
|
| 183 |
interpreted as follows:
|
| 184 |
|
| 185 |
+
- if the pack is a template parameter pack, the element is
|
| 186 |
+
- a *typedef-name* for a type template parameter pack,
|
| 187 |
+
- an *id-expression* for a constant template parameter pack, or
|
| 188 |
+
- a *template-name* for a template template parameter pack
|
| 189 |
+
|
| 190 |
+
designating the iᵗʰ corresponding type, constant, or template template
|
| 191 |
+
argument;
|
| 192 |
- if the pack is a function parameter pack, the element is an
|
| 193 |
*id-expression* designating the iᵗʰ function parameter that resulted
|
| 194 |
from instantiation of the function parameter pack declaration;
|
|
|
|
| 195 |
- if the pack is an *init-capture* pack, the element is an
|
| 196 |
*id-expression* designating the variable introduced by the iᵗʰ
|
| 197 |
*init-capture* that resulted from instantiation of the *init-capture*
|
| 198 |
+
pack declaration; otherwise
|
| 199 |
+
- if the pack is a structured binding pack, the element is an
|
| 200 |
+
*id-expression* designating the $i^\textrm{th}$ structured binding in
|
| 201 |
+
the pack that resulted from the structured binding declaration.
|
| 202 |
|
| 203 |
When N is zero, the instantiation of a pack expansion does not alter the
|
| 204 |
syntactic interpretation of the enclosing construct, even in cases where
|
| 205 |
omitting the pack expansion entirely would otherwise be ill-formed or
|
| 206 |
would result in an ambiguity in the grammar.
|
| 207 |
|
| 208 |
The instantiation of a `sizeof...` expression [[expr.sizeof]] produces
|
| 209 |
an integral constant with value N.
|
| 210 |
|
| 211 |
+
When instantiating a *pack-index-expression* P, let K be the index of P.
|
| 212 |
+
The instantiation of P is the *id-expression* `E_K`.
|
| 213 |
+
|
| 214 |
+
When instantiating a *pack-index-specifier* P, let K be the index of P.
|
| 215 |
+
The instantiation of P is the *typedef-name* `E_K`.
|
| 216 |
+
|
| 217 |
+
The instantiation of an *alignment-specifier* with an ellipsis produces
|
| 218 |
+
`E₁` `E₂` … `E_N`.
|
| 219 |
+
|
| 220 |
The instantiation of a *fold-expression* [[expr.prim.fold]] produces:
|
| 221 |
|
| 222 |
- `(` `((`E₁ *op* E₂`)` *op* ⋯`)` *op* $\mathtt{E}_N$ `)` for a unary
|
| 223 |
left fold,
|
| 224 |
- `(` E₁ *op* `(`⋯ *op* `(`$\mathtt{E}_{N-1}$ *op* $\mathtt{E}_N$`))`
|
|
|
|
| 230 |
|
| 231 |
In each case, *op* is the *fold-operator*. For a binary fold, E is
|
| 232 |
generated by instantiating the *cast-expression* that did not contain an
|
| 233 |
unexpanded pack.
|
| 234 |
|
| 235 |
+
[*Example 7*:
|
| 236 |
|
| 237 |
``` cpp
|
| 238 |
template<typename ...Args>
|
| 239 |
bool all(Args ...args) { return (... && args); }
|
| 240 |
|
|
|
|
| 257 |
| `&&` | `true` |
|
| 258 |
| `||` | `false` |
|
| 259 |
| `,` | `void()` |
|
| 260 |
|
| 261 |
|
| 262 |
+
A fold expanded constraint is not instantiated [[temp.constr.fold]].
|
| 263 |
+
|
| 264 |
The instantiation of any other pack expansion produces a list of
|
| 265 |
elements `E₁`, `E₂`, …, `E_N`.
|
| 266 |
|
| 267 |
[*Note 1*: The variety of list varies with the context:
|
| 268 |
*expression-list*, *base-specifier-list*, *template-argument-list*,
|
| 269 |
etc. — *end note*]
|
| 270 |
|
| 271 |
When N is zero, the instantiation of the expansion produces an empty
|
| 272 |
list.
|
| 273 |
|
| 274 |
+
[*Example 8*:
|
| 275 |
|
| 276 |
``` cpp
|
| 277 |
template<class... T> struct X : T... { };
|
| 278 |
template<class... T> void f(T... values) {
|
| 279 |
X<T...> x(values...);
|