staticFold

Static version of std.algorithm.reduce (or fold). Expects that F takes accumulator as first argument and a value as second argument. * First value of T have to be a initial value of accumulator.

template staticFold (
T...
) {
enum staticFold;
}

Examples

Example

1 template summ(T...)
2 {
3     enum summ = T[0] + T[1];
4 }
5 
6 static assert(staticFold!(summ, 0, 1, 2, 3, 4) == 10);
7 
8 template preferString(T...)
9 {
10     static if(is(T[0] == string))
11         alias preferString = T[0];
12     else
13         alias preferString = T[1];
14 }
15 
16 static assert(is(staticFold!(preferString, void, int, string, bool) == string));
17 static assert(is(staticFold!(preferString, void, int, double, bool) == bool));

Meta