Simple as that, suppose
    uint[uint] aa;
Any range supports carrying an index. Not so does the Range returned by byKey and byValue.
    foreach (i, k; aa.byKey) { }
and
    foreach (i, v; aa.byValue) { }
both don't compile.

Reason (I found out by chance):

If the key or value type is a std.typecons.Tuple, iteration over aa.by* decomposes the Tuple if there is the right number of arguments. For 2-Tuples, there cannot be both possible.

    alias Tup = Tuple!(int, int);
    int[Tup] it;
    Tup[int] ti;

    foreach (x, y; it.byKey) { }
    foreach (x, y; ti.byValue) { }

Why is this undocumented? http://dlang.org/spec/hash-map.html doesn't mention Tuples at all! Why is this useful? Anyone can decompose the Tuple with .expand if they like. I would prefer allowing an index.

If it does not meet the spec, is it a bug then?

Reply via email to