Nested slicing

Jason House jason.james.house at gmail.com
Mon Mar 31 08:55:54 PDT 2008


Koroskin Denis Wrote:

> One last thing about dollar notation in array slicing.
> Shouldn't the following piece of code generate a compile-time error?
> 
> import std.stdio;
> 
> int main()
> {
>      int[] outer = [0, 1, 2, 3, 4];
>      int[] inner = [5, 4, 3, 2, 1];
> 
>      int[] slice = outer[0..inner[$-1]]; < Error: shadowing declaration  
> __dollar is deprecated
> 
>      writefln(slice.length);
> 
>      return 0;
> }


Absolutely!  Shadowed variable declarations can be a tough thing to spot when things aren't working right.  I'd just say to use outer.length or inner.length to resolve ambiguity.



More information about the Digitalmars-d mailing list