I'm back

Jonathan M Davis jmdavisProg at gmx.com
Fri Nov 23 12:32:47 PST 2012


On Friday, November 23, 2012 16:34:51 jerro wrote:
> > What if we did it so that transient ranges would have to define
> > transient property (as was previously proposed), and
> > isInputRange, isForwardRange and others would get an additional
> > parameter allowTransient. The default value of that argument
> > would be false, so those templates would evaluate to false for
> > transient ranges by default. Then algorithms that can work with
> > transient ranges would use
> > ...
> > if(isInputRange!(R, true))
> > 
> > instead of
> > 
> > if(isInputRange!R)
> > 
> > The algorithms that don't support transient ranges would not
> > need to be changed.  Wrapper ranges such as map's result would
> > define transient property if the wrapped range defines it.
> 
> Just to clarify, by "transient ranges would have to define
> transient property" I meant just that this should be true for
> transient ranges: is(typeof(R.transient)). So transient could
> just be an enum. I didn't mean there would be a transient
> property that would return a transient version of the range.

It's not worth the extra complication. Every algorithm ever written then has 
to worry about it (though clearly many outside of Phobos wouldn't bother), and 
it's yet another thing that anyone writing a range-based function has to take 
into account. Any function which doesn't take it into account will then end up 
with wrong and bizarre behavior when it's given a range with a transient 
front. To be correct, most range-based functions would have to add template 
constraints to block ranges which mark themselves as transient.

We're talking about a rare use case here. I don't think that it even occurs to 
most people that it's possible to create a range with a transient front - 
certainly almost nothing in Phobos was written with that possibility in mind, 
and that's code written by the people who know ranges the best. Only two 
ranges in all of Phobos actually behave this way (ByLine and ByChunk), and 
people usually _complain_ about them working that way rather than being happy 
about it.

It's just not worth complicating ranges further by supporting ranges with a 
transient front. At most, supporting them under restricted circumstances might 
make sense (e.g. just input ranges), but not even that's worth it IMHO. 

- Jonathan M Davis


More information about the Digitalmars-d mailing list