[expr.prim.fold] (original) (raw)
7 Expressions [expr]
7.5 Primary expressions [expr.prim]
7.5.7 Fold expressions [expr.prim.fold]
A fold expression performs a fold of a pack ([temp.variadic]) over a binary operator.
fold-operator: one of
- - * / % ^ & | << >>
+= -= *= /= %= ^= &= |= <<= >>= =
== != < > <= >= && || , .* ->*
An expression of the form(... op e)where op is a fold-operatoris called a unary left fold.
An expression of the form(e op ...)where op is a fold-operatoris called a unary right fold.
Unary left folds and unary right folds are collectively called unary folds.
An expression of the form(e1 op1 ... op2 e2)where op1 and op2 are fold-operator_s_is called a binary fold.
In a binary fold,op1 and _op2_shall be the same fold-operator, and either e1shall contain an unexpanded pack or e2shall contain an unexpanded pack, but not both.
If e2 contains an unexpanded pack, the expression is called a binary left fold.
If e1 contains an unexpanded pack, the expression is called a binary right fold.
[Example 1: template<typename ...Args> bool f(Args ...args) { return (true && ... && args); } template<typename ...Args> bool f(Args ...args) { return (args + ... + args); } — _end example_]
A fold expression is a pack expansion.