KeyType, ValueType traits for hashes
Andrej Mitrovic
andrej.mitrovich at gmail.com
Mon Jan 23 14:44:15 PST 2012
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));
}
More information about the Digitalmars-d-learn
mailing list