I am trying to create a function that tests membership in nested associative array, however the function I create below, only accepts keys of the same type and if given keys of different types it does not compile, help would be appreciated.
This is a example of what Im talking about.
import std.stdio;
void main()
{
int[int][int] aa1;
aa1[1][2] = 3;
writeln(contains(aa1, 1, 2)); //returns true as expected
int[int][string] aa2;
aa2["1"][2] = 3;
writeln(contains(aa2, "1", 2)); //does not compile because of this line
}
bool contains(M, K...)(M map, K keys)
{
foreach(key; keys)
if(key in map)
return contains(map[key], keys[1 .. $]);
else
return false;
return true;
}