Tutorial by Examples

Unary folds are used to fold parameter packs over a specific operator. There are 2 kinds of unary folds: Unary Left Fold (... op pack) which expands as follows: ((Pack1 op Pack2) op ...) op PackN Unary Right Fold (pack op ...) which expands as follows: Pack1 op (... (Pack(N-1) op Pac...
Binary folds are basically unary folds, with an extra argument. There are 2 kinds of binary folds: Binary Left Fold - (value op ... op pack) - Expands as follows: (((Value op Pack1) op Pack2) op ...) op PackN Binary Right Fold (pack op ... op value) - Expands as follows: Pack1 op (......
It is a common operation to need to perform a particular function over each element in a parameter pack. With C++11, the best we can do is: template <class... Ts> void print_all(std::ostream& os, Ts const&... args) { using expander = int[]; (void)expander{0, (void(...

Page 1 of 1