Binary Folds

suggest change

Binary folds are basically unary folds, with an extra argument.

There are 2 kinds of binary folds:

(((Value op Pack1) op Pack2) op ...) op PackN
Pack1 op (... op (Pack(N-1) op (PackN op Value)))

Here is an example:

template<typename... Ts>
int removeFrom(int num, Ts... args)
    return (num - ... - args); //Binary left fold
    // Note that a binary right fold cannot be used
    // due to the lack of associativity of operator-

int result = removeFrom(1000, 5, 10, 15); //'result' is 1000 - 5 - 10 - 15 = 970

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents