[Issue 16149] foreach_reverse can't handle index variable of type int

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jun 12 05:03:53 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16149

--- Comment #6 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
(In reply to Steven Schveighoffer from comment #5)
> int x = a.length would continue to be invalid (on 64-bit CPU). It's just for
> foreach_reverse.

then i'll inevitably ask why `int x = a.length;` is invalid, but
`foreach_reverse (int x, v; a)` is valid. that `foreach` obviously does the
assign under the hood (at least this is the most practical way to imagine it).

the only way to skip that "hidden assign" is to redefive `foreach_reverse`
completely — by still using increasing index in it, so x will go from 0 upto
limit. otherwise you just introducing a random pseudo-solution by randomly
breaking the rules.

--


More information about the Digitalmars-d-bugs mailing list