is this considered inconsistency?

mw mingwu at gmail.com
Sun Mar 21 17:01:27 UTC 2021


On Sunday, 21 March 2021 at 16:47:41 UTC, Dennis wrote:
> On Sunday, 21 March 2021 at 15:55:04 UTC, mw wrote:
>> Why can't the a[0 .. -1] just return empty range, when end <= 
>> start, as in a[0 ..  0]? and also in foreach (i;   0 .. -1 )?
>
> In `foreach (i; 0 .. -1)`, `i` is typed `int`. In a slice, the 
> indices are of type `size_t` which is an unsigned integer type. 
> -1 underflows to `ulong.max` (on 64-bit) which is why you get a 
> range violation.

Ahh, This explains.

> There's also a point to be made that the implicit conversion 
> from signed to unsigned integers should not be allowed, that's 
> a separate discussion.

Indeed, this shouldn't be allowed, bite by this a number of 
times. Is there a DIP on this already?


More information about the Digitalmars-d mailing list