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