I haven't found these in Phobos, so if they're really not in
std.traits or anywhere do you think I should make a pull request for
this?

import std.traits;

template KeyType(T)
    if (isAssociativeArray!T)
{
    alias typeof(T.keys()[0]) KeyType;
}

template ValueType(T)
    if (isAssociativeArray!T)
{
    alias typeof(T.values()[0]) ValueType;
}

void main()
{
    alias string[int] Hash;
    static assert(is(KeyType!Hash == int));
    static assert(is(ValueType!Hash == string));
}

Reply via email to