digitalmars.D.learn - Fix iota for unsigned reverse counting
- Brad Anderson (20/20) Apr 26 2012 Issue 7982  is caused by io...
Issue 7982  is caused by iota.length()  not working properly with unsigned values where the begin is greater than the end (the larger value is subtracted from the smaller value causing it to wrap around). I asked Andrei in IRC if replacing: return unsigned((pastLast - current) / step); with: return unsigned(((cast(Signed!Value)pastLast) - (cast(Signed!Value)current)) / step); was a sane approach. Although it does seem to fix the problem (though I haven't tested thoroughly) Andrei said it wasn't sane. I'm not sure what would be a better approach so I'm asking for ideas here. (why does std.traits have unsigned() to take advantage of IFTI but no signed() equivalent?)  http://d.puremagic.com/issues/show_bug.cgi?id=7982  https://github.com/D-Programming-Language/phobos/blob/master/std/range.d#L4383 Regards, Brad Anderson
Apr 26 2012