ValueType

Takes a type which is an associative array and evaluates to the type of the values in that associative array.

alias ValueType(V : V[K], K) = V

Examples

static assert(is(ValueType!(int[string]) == int));
static assert(is(ValueType!(string[int]) == string));

static assert(is(ValueType!(string[const int]) == string));
static assert(is(ValueType!(const int[string]) == const int));

struct S
{
    int i;
}

string[S] aa1;
static assert(is(ValueType!(typeof(aa1)) == string));

S[string] aa2;
static assert(is(ValueType!(typeof(aa2)) == S));

ValueType!(typeof(aa1)) value1 = "foo";
ValueType!(typeof(aa2)) value2 = S(42);

// If the given type is not an AA, then ValueType won't compile.
static assert(!__traits(compiles, ValueType!int));
static assert(!__traits(compiles, ValueType!(int[])));

See Also

Meta