tmp/tmpv1n9f4st/{from.md → to.md}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
### Fold expressions <a id="expr.prim.fold">[[expr.prim.fold]]</a>
|
| 2 |
|
| 3 |
-
A fold expression performs a fold of a
|
| 4 |
-
|
| 5 |
|
| 6 |
``` bnf
|
| 7 |
fold-expression:
|
| 8 |
'(' cast-expression fold-operator '...' ')'
|
| 9 |
'(' '...' fold-operator cast-expression ')'
|
|
@@ -22,20 +22,19 @@ fold-operator: one of
|
|
| 22 |
An expression of the form `(...` *op* `e)` where *op* is a
|
| 23 |
*fold-operator* is called a *unary left fold*. An expression of the form
|
| 24 |
`(e` *op* `...)` where *op* is a *fold-operator* is called a *unary
|
| 25 |
right fold*. Unary left folds and unary right folds are collectively
|
| 26 |
called *unary folds*. In a unary fold, the *cast-expression* shall
|
| 27 |
-
contain an unexpanded
|
| 28 |
|
| 29 |
An expression of the form `(e1` *op1* `...` *op2* `e2)` where *op1* and
|
| 30 |
*op2* are *fold-operator*s is called a *binary fold*. In a binary fold,
|
| 31 |
*op1* and *op2* shall be the same *fold-operator*, and either `e1` shall
|
| 32 |
-
contain an unexpanded
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
fold*.
|
| 37 |
|
| 38 |
[*Example 1*:
|
| 39 |
|
| 40 |
``` cpp
|
| 41 |
template<typename ...Args>
|
|
@@ -43,11 +42,11 @@ bool f(Args ...args) {
|
|
| 43 |
return (true && ... && args); // OK
|
| 44 |
}
|
| 45 |
|
| 46 |
template<typename ...Args>
|
| 47 |
bool f(Args ...args) {
|
| 48 |
-
return (args + ... + args); // error: both operands contain unexpanded
|
| 49 |
}
|
| 50 |
```
|
| 51 |
|
| 52 |
— *end example*]
|
| 53 |
|
|
|
|
| 1 |
### Fold expressions <a id="expr.prim.fold">[[expr.prim.fold]]</a>
|
| 2 |
|
| 3 |
+
A fold expression performs a fold of a pack [[temp.variadic]] over a
|
| 4 |
+
binary operator.
|
| 5 |
|
| 6 |
``` bnf
|
| 7 |
fold-expression:
|
| 8 |
'(' cast-expression fold-operator '...' ')'
|
| 9 |
'(' '...' fold-operator cast-expression ')'
|
|
|
|
| 22 |
An expression of the form `(...` *op* `e)` where *op* is a
|
| 23 |
*fold-operator* is called a *unary left fold*. An expression of the form
|
| 24 |
`(e` *op* `...)` where *op* is a *fold-operator* is called a *unary
|
| 25 |
right fold*. Unary left folds and unary right folds are collectively
|
| 26 |
called *unary folds*. In a unary fold, the *cast-expression* shall
|
| 27 |
+
contain an unexpanded pack [[temp.variadic]].
|
| 28 |
|
| 29 |
An expression of the form `(e1` *op1* `...` *op2* `e2)` where *op1* and
|
| 30 |
*op2* are *fold-operator*s is called a *binary fold*. In a binary fold,
|
| 31 |
*op1* and *op2* shall be the same *fold-operator*, and either `e1` shall
|
| 32 |
+
contain an unexpanded pack or `e2` shall contain an unexpanded pack, but
|
| 33 |
+
not both. If `e2` contains an unexpanded pack, the expression is called
|
| 34 |
+
a *binary left fold*. If `e1` contains an unexpanded pack, the
|
| 35 |
+
expression is called a *binary right fold*.
|
|
|
|
| 36 |
|
| 37 |
[*Example 1*:
|
| 38 |
|
| 39 |
``` cpp
|
| 40 |
template<typename ...Args>
|
|
|
|
| 42 |
return (true && ... && args); // OK
|
| 43 |
}
|
| 44 |
|
| 45 |
template<typename ...Args>
|
| 46 |
bool f(Args ...args) {
|
| 47 |
+
return (args + ... + args); // error: both operands contain unexpanded packs
|
| 48 |
}
|
| 49 |
```
|
| 50 |
|
| 51 |
— *end example*]
|
| 52 |
|