I've got a hash map T[][T] with keys of T and values of T[]. For some reason, I'll need a range of tuples (t1, t2), where t1 is a key and t2 is an element of the array t1 maps to. To have them in order would be great, but is not necessary.

I just wrote my own range type and it works. But I wonder how would I do it with phobos utilities?

I came up with this:

int[][int] hash = [1 :[1,2,3,4], 2:[3,1,2,3], 4:[2,3,1,3]];
auto x = hash.keys.map!(x => tuple(x, hash[x]))
                  .map!(x => zip(repeat(x[0]), x[1]));

Is there any other way to create a range of simple (key,value) pairs for the array, but needs to allocate (hash.keys return an array of keys) and then again look up every key.

We can loop over (key,value) pairs of the AA with foreach, but I guess there is no standard way to create a range from a foreach-compatible delegate? Or even get a hand on this delegate?

Reply via email to