arbitrary type to visit/reduce
struct type conforming assertValidReducer requirements used to do actual calculations/checks on the type
value of type Reducer.Result calculated by calling Reducer.visit on each nested type of T recursively and reducing via Reducer.accumulate.
Example reducer that counts amount of integer typed entities accessible though the base types (i.e. fields and referenced types):
static struct ExampleReducer { alias int Result; const seed = 0; Result accumulate ( Result accum, Result next ) { return accum + next; } Result visit ( T ) ( ) { if (isIntegerType!(T)) return 1; } } static assert (ReduceType!(int, ExampleReducer) == 1); static assert (ReduceType!(int[int], ExampleReducer) == 2);
Reduces definition of a type to single value using provided Reducer.
If Reducer does not specify seed and accumulate explicitly, defaults to false seed and a || b accumulator. Result must alias bool in such case.
NB: currently ReduceType does not work with types which have recursive definition, for example struct S { S* ptr; }, crashing compiler at CTFE stage. This will be improved in the future.