KeyType, ValueType traits for hashes

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Jan 23 22:43:36 PST 2012


But I did implement them poorly, this is better:

import std.traits;

template KeyType(AA)
    if (isAssociativeArray!AA)
{
    static if (is(AA V : V[K], K))
    {
        alias K KeyType;
    }
}

template ValueType(AA)
    if (isAssociativeArray!AA)
{
    static if (is(AA V : V[U], U))
    {
        alias V ValueType;
    }
}


More information about the Digitalmars-d-learn mailing list