Range violation instead of empty slice on a[3 .. 2]

SimonN via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Nov 21 11:00:51 PST 2015


On Saturday, 21 November 2015 at 18:28:51 UTC, BBaz wrote:
> this is only an error if bounds checking is not turned on. If 
> you compile your example with DMD option "-boundscheck=off", 
> nothing happens, and the slice will be equal (here) to a[3..$];

Thanks for the hint, I tested this with -boundscheck=off. Then, 
a[3..2] generates a slice length of (size_t.max), again different 
from what I might want.

If the reason for this behavior (huge slice length instead of 
null slice) is performance during disabled bounds checking, then 
I'm fine with having to make the extra check.

-- Simon


More information about the Digitalmars-d-learn mailing list