[Issue 10009] foreach_reverse and AA.byKey/byValue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 3 15:59:39 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10009



--- Comment #9 from bearophile_hugs at eml.cc 2013-05-03 15:59:38 PDT ---
(In reply to comment #8)

> However, I don't think foreach_reverse is valid for this use case.  An AA is
> only forward-traversable.  foreach_reverse is not possible, as buckets are
> stored as singly-linked lists.  If you want that, you need to first capture it
> as an array.

Yet this compiles:

import std.stdio: writeln;
void main() {
    auto aa = [1: 2, 2: 3];
    foreach (k, v; aa)
        writeln(k, " ", v);
    foreach_reverse (k, v; aa)
        writeln(k, " ", v);
}


And outputs:

1 2
2 3
1 2
2 3

The foreach seems to give the same sequence as the foreach_reverse :-)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list