Get rid of isInfinite()?

Jonathan M Davis jmdavisProg at gmx.com
Mon Jun 25 11:27:18 PDT 2012


On Monday, June 25, 2012 19:43:00 Mehrdad wrote:
> On Monday, 25 June 2012 at 17:38:55 UTC, Steven Schveighoffer
> 
> wrote:
> > I think you misunderstand an infinite range. There are plenty
> > of truly infinite ranges available.
> > 
> > An example infinite range:
> > 
> > struct Infinite
> > {
> > 
> > int x;
> > @property int front() { return x;}
> > void popFront() {}
> > enum empty = false;
> > 
> > }
> > 
> > length has nothing to do with infinite ranges. In fact,
> > infinite ranges should have no length member.
> > 
> > -Steve
> 
> Oh, I see. So they're truly infinite, not just unbounded.
> 
> In that case, how do you make a random-access wrapper around an
> input range?
> (i.e. What do you use for 'length'?)

Input ranges cannot be random access. Iterating over them consumes them, and 
you have no way of knowing their length other then iterating over them and 
counting (which would consume them), so they have no length property. If you 
want an input range to be treated as a forward range or random access range, 
you're going to need to copy it into something first.

- Jonathan M Davis


More information about the Digitalmars-d mailing list