Get rid of isInfinite()?

Jonathan M Davis jmdavisProg at gmx.com
Mon Jun 25 16:03:47 PDT 2012


On Tuesday, June 26, 2012 00:46:40 Mehrdad wrote:
> On Monday, 25 June 2012 at 18:29:45 UTC, Bernard Helyer wrote:
> > On Monday, 25 June 2012 at 17:43:01 UTC, Mehrdad wrote:
> >> In that case, how do you make a random-access wrapper around
> >> an input range?
> > 
> > You don't. If you could, they wouldn't be an input range.
> 
> Wait, what?
> 
> I don't see why you _shouldn't_ be able to create a random-access
> wrapper that lazily reads as much data as it needs to, in order
> to satisfy a random read.
> 
> i.e. I see no obstacle, at least conceptually, other than the
> fact you're saying you can't do it.

You can't do it as a proper random-access range. To do that, it would have to 
be a forward range, and if it's not a forward range already, then presumably, 
there's a reason why it can't be. You could easily tell it to give you the nth 
element, but that would require consuming all of the preceding elements to get 
to it. You could store those elements internally as you iterate over them, but 
normally, they'd be gone, meaning that skipping to the nth element would mean 
losing all of the preceding elements.

Regardless, unless you can find a way to define a save function which will 
return a copy of the range and be able to iterate over both of them separately 
and get exactly the same elements, then you can't have anything more than an 
input range as far as how the various ranges are defined goes. If you can 
somehow figure out how to do that via buffering, then you could make it a 
forward range as well as whatever other range types you could define the 
functions for, but you'd have to figure out a way to define save.

- Jonathan M Davis


More information about the Digitalmars-d mailing list