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: ((num - a) - b) - c
    // A binary right fold, (args - ... - num), is legal but associates
    // the other way, so it does not compute num - 5 - 10 - 15.
}

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

Feedback about page:

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



Table Of Contents