Tricky semantics of ranges & potentially numerous Phobos bugs

Jonathan M Davis jmdavisProg at gmx.com
Wed Oct 17 12:14:00 PDT 2012


On Wednesday, October 17, 2012 12:39:13 Andrei Alexandrescu wrote:
> On 10/16/12 1:28 PM, Jonathan M Davis wrote:
> > So, it's fine that ByLine is a range as long as we're willing to put up
> > with it not working with a lot of range-based functions because of its
> > abnormal behavior. But I don't think that it's at all reasonable for
> > range-based functions in general to not be able to rely on front
> > returning the same type every time or on its value disappearing or
> > becoming invalid in some way after a call to popFront. That's completely
> > untenable IMHO.
> 
> Then what is to you the difference between an input range and a forward
> range?

Whether you can get a copy of the range. If you call save, you can save its 
current state and have two copies of the range to operate on separately, 
That's completely different from whether front can be kept around or not. It's 
perfectly possible to have an input range whose previous front does not get 
invalidated by a call to popFront. ByLine would be that way if it allocated a 
new buffer instead of reusing the old one. It just doesn't do that because it's 
less efficient to do so.

- Jonathan M Davis


More information about the Digitalmars-d mailing list