Get rid of isInfinite()?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Jun 25 10:38:55 PDT 2012
On Mon, 25 Jun 2012 13:26:22 -0400, Mehrdad <wfunction at hotmail.com> wrote:
> I feel like isInfinite is useless for typical cases... the only
> "infinite" (perhaps I should call it "unbounded" instead?) range I've
> ever realistically come across is a stream, like console input or a
> network stream.
>
> Of course, isInfinite doesn't make any sense for any type of wrapper
> around console input -- is it true or false?
> You can't tell, because it depends on whether the input is redirected.
> If the console input was redirected, then it would be finite, with a
> certain length (the length of the file).
> If not, then it would be infinite (er, unbounded).
>
> So IMHO, we should deprecate isInfinite entirely, and instead rely on
> length being size_t.max.
>
> Not only would it make more sense, but it would make it possible to
> create a random-access wrapper around an input range (like console
> input), which lazily fetches its data.
> Then you can work with console input like a regular string!
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
More information about the Digitalmars-d
mailing list