'int' is enough for 'length' to migrate code from x86 to x64

Daniel Murphy via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 21 00:16:56 PST 2014


"Andrei Alexandrescu"  wrote in message 
news:m4l711$1t39$1 at digitalmars.com...

> The most difficult pattern that comes to mind is the "long arrow" operator 
> seen in backward iteration:
>
> void fun(int[] a)
> {
>      for (auto i = a.length; i --> 0; )
>      {
>          // use i
>      }
> }

Over the years most of my unsigned-related bugs have been from screwing up 
various loop conditions.  Thankfully D solves this perfectly with:

void fun(int[] a)
{
    foreach_reverse(i, 0...a.length)
    {
    }
}

So I never have to write those again. 



More information about the Digitalmars-d mailing list