foreach_reverse is better than ever

Steven Schveighoffer schveiguy at yahoo.com
Mon Feb 15 13:00:04 PST 2010


On Sun, 14 Feb 2010 00:53:31 -0500, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Gone, that is. Walter agreed to remove it.
>
> To achieve the functionality of
>
> foreach_reverse (r) { ... }
>
> use
>
> foreach (retro(r)) { ... }
>
> using retro in std.range.

Will retro work on AA's?

Other than that (and how to do foreach(1..100) that others have brought  
up) I think this is a great move.

BTW, for those bemoaning the loss of opApplyReverse, it is easy to change  
this:

struct S(T)
{
    int opApplyReverse(int delegate(ref T t) dg) {...}
}

S!int s;
foreach_reverse(i; s) {...}

into this:

struct S(T)
{
    int inReverse(int delegate(ref T t) dg) {...}
}

S!int s;
foreach(i; &s.inReverse){...}

Of course, I'd prefer it without the &, but that is a separate issue (see  
bug http://d.puremagic.com/issues/show_bug.cgi?id=2498)

Also, while your attention is focused on foreach, look at this bug:  
http://d.puremagic.com/issues/show_bug.cgi?id=2443

:)

-Steve



More information about the Digitalmars-d mailing list