May 2017
Intermediate to advanced
590 pages
17h 18m
English
When the compiler encounters a fold expression, it expands it in one of the following expressions:
| Expression | Expansion |
| (... op pack) | ((pack$1 op pack$2) op ...) op pack$n |
| (init op ... op pack) | (((init op pack$1) op pack$2) op ...) op pack$n |
| (pack op ...) | pack$1 op (... op (pack$n-1 op pack$n)) |
| (pack op ... op init) | pack$1 op (... op (pack$n-1 op (pack$n op init))) |
When the binary form is used, the operator on both the left-hand and right-hand side of the ellipses must be the same, and the initialization value must not contain an unexpanded parameter pack.
The following binary operators are supported with fold expressions:
| + | - | * | / | % | ^ | & | | | = | < | > | << |
| >> | += | -= | *= | /= | %= | ^= | &= | |= | <<= | >>= | == |
| != | <= | >= | && | || |
Read now
Unlock full access