tmp/tmpbbh4qzgb/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Fold expressions <a id="expr.prim.fold">[[expr.prim.fold]]</a>
|
| 2 |
+
|
| 3 |
+
A fold expression performs a fold of a template parameter pack (
|
| 4 |
+
[[temp.variadic]]) over a binary operator.
|
| 5 |
+
|
| 6 |
+
``` bnf
|
| 7 |
+
fold-expression:
|
| 8 |
+
'(' cast-expression fold-operator '...' ')'
|
| 9 |
+
'(' '...' fold-operator cast-expression ')'
|
| 10 |
+
'(' cast-expression fold-operator '...' fold-operator cast-expression ')'
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
``` bnf
|
| 14 |
+
%% Ed. note: character protrusion would misalign operators with leading `-`.
|
| 15 |
+
|
| 16 |
+
fold-operator: one of
|
| 17 |
+
'+ ' '- ' '* ' '/ ' '% ' '^ ' '& ' '| ' '<< ' '>> '
|
| 18 |
+
'+=' '-=' '*=' '/=' '%=' '^=' '&=' '|=' '<<=' '>>=' '='
|
| 19 |
+
'==' '!=' '< ' '> ' '<=' '>=' '&&' '||' ', ' '.* ' '->*'
|
| 20 |
+
```
|
| 21 |
+
|
| 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 parameter 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 parameter pack or `e2` shall contain an unexpanded
|
| 33 |
+
parameter pack, but not both. If `e2` contains an unexpanded parameter
|
| 34 |
+
pack, the expression is called a *binary left fold*. If `e1` contains an
|
| 35 |
+
unexpanded parameter pack, the expression is called a *binary right
|
| 36 |
+
fold*.
|
| 37 |
+
|
| 38 |
+
[*Example 1*:
|
| 39 |
+
|
| 40 |
+
``` cpp
|
| 41 |
+
template<typename ...Args>
|
| 42 |
+
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 parameter packs
|
| 49 |
+
}
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
— *end example*]
|
| 53 |
+
|