Is this a bug in iota?
Brad Anderson
eco at gnuk.net
Wed Apr 18 20:32:38 PDT 2012
The following code:
import std.range;
void main()
{
auto i = iota(3);
writeln(i.front, ", length: ", i.length); i.popFront();
writeln(i.front, ", length: ", i.length); i.popFront();
writeln(i.front, ", length: ", i.length); i.popFront();
writeln(i.front, ", length: ", i.length); i.popFront();
writeln(i.front, ", length: ", i.length); i.popFront();
}
Outputs:
0, length: 3
1, length: 2
2, length: 1
3, length: 0
4, length: 4294967295
You can popFront() for as long as you want well passed the
length. Obviously popping off the front of a zero length range
isn't valid but I would have expected a range violation to occur
rather than it to silently continuing the series with a wrapped
around length.
I was actually looking for an infinite counting range when I
stumbled across this. sequence() works but something even simpler
like iota() would be better. I suspect, however, that this
behavior was unintended.
Regards,
Brad Anderson
More information about the Digitalmars-d-learn
mailing list