cpp/language/fold

Reduces a  over a binary operator.

Syntax
@1@ unary right fold @2@ unary left fold @3@ binary right fold @4@ binary left fold

Note that the opening and closing parentheses are a required part of the fold expression.

Explanation
The instantiation of a fold expression expands the expression as follows:

@1@ Unary right fold   becomes   ...     @2@ Unary left fold    becomes     ...   @3@ Binary right fold      becomes   ...       @4@ Binary left fold      becomes       ...

(where is the number of elements in the pack expansion)

For example,

When a unary fold is used with a pack expansion of length zero, only the following operators are allowed: @1@ Logical AND. The value for the empty pack is @2@ Logical OR. The value for the empty pack is @3@ The comma operator. The value for the empty pack is