is this considered inconsistency?
mw
mingwu at gmail.com
Sun Mar 21 15:55:04 UTC 2021
https://run.dlang.io/is/VOGlGN
void main()
{
import std.stdio: writeln;
{
// example from "Introduction to Algorithms" Cormen et
al., p 146
int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ];
foreach (i; 0 .. 1 ) writeln(i); // 0
foreach (i; 0 .. 0 ) writeln(i); // no output
foreach (i; 0 .. -1 ) writeln(i); // no output
foreach (i; a[0 .. 1]) writeln(i); // 4
foreach (i; a[0 .. 0]) writeln(i); // no output
foreach (i; a[0 .. -1]) writeln(i); // Range violation
}
}
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 )?
More information about the Digitalmars-d
mailing list