ReduceType

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.

template ReduceType (
T
Reducer
) {}

Members

Static variables

ReduceType
auto ReduceType;
Undocumented in source.

Parameters

T

arbitrary type to visit/reduce

Reducer

struct type conforming assertValidReducer requirements used to do actual calculations/checks on the type

Return Value

value of type Reducer.Result calculated by calling Reducer.visit on each nested type of T recursively and reducing via Reducer.accumulate.

Examples

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);

Meta