Negative index range violation

Adam D. Ruppe destructionator at gmail.com
Thu Feb 22 00:26:42 UTC 2018


On Thursday, 22 February 2018 at 00:13:43 UTC, SrMordred wrote:
> string x = "123";
> auto c = x.ptr;
> c++;
> writeln(c[-1]); // 1

That's only happening because pointers bypass range checks.

> writeln(c[-1..0]); //BOOM Range violation

But with a slice negative indexes are never allowed, even on a 
pointer.


More information about the Digitalmars-d-learn mailing list