Is this a bug in iota?
Ali Çehreli
acehreli at yahoo.com
Thu Apr 19 00:49:35 PDT 2012
On 04/18/2012 08:45 PM, Brad Anderson wrote:
> On Thursday, 19 April 2012 at 03:37:00 UTC, bearophile wrote:
>> Brad Anderson:
>>> 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 agree. I think it is just an oversight in iota()'s general
implementation because its floating point specialization does have an
assert check in popFront():
import std.range;
void main()
{
auto r = iota(1.0); // <-- note 'double' type
r.popFront();
r.popFront(); // <-- assertion failure
}
>> I think it's a matter of design and it's a matter of having an
>> alternative Phobos release that contains asserts too. Adding the test
>> slows down something (iota) that must be as fast as possible. And
>> currently asserts are removed from the compiled Phobos...
>>
>> Bye,
>> bearophile
>
> Since iota is a template doesn't that mean it's not in phobos.lib but
> rather generated and built into my application? I'm not compiling in
> release mode so I would think any bounds checking it had would remain (I
> haven't yet looked at the source to see if there are any checks). I can
> definitely see stripping any bounds checking from a release build, of
> course.
I think this warrants an enhancement request. Thank you. :)
>
> Doing this same thing to a slice of an array does throw a Range
> Violation exception in release (and asserts in debug).
>
> Regards,
> Brad Anderson
Ali
More information about the Digitalmars-d-learn
mailing list