On Thu, 27 Mar 2014 16:58:12 -0400, Walter Bright <[email protected]> wrote:

On 3/27/2014 12:50 PM, Andrei Alexandrescu wrote:
Yah, agreed. -- Andrei

Completely unworkable. To determine if a range is empty or not, it may have to actually read from its input. TTYs are an example. Although empty may then cache the result, and not read the second time it is called, an observer of TTY could see that an item was read from the TTY.

In the land of ranges, it's construction and popFront that generally advances the range. Empty does not. This is why assert(!empty) is all over the place, it's considered to be non-destructive.

Note that a stream makes a terrible range, simply because of what you say -- reading is destructive, and determining emptiness is dependent on reading. You need a buffered stream to make a good range, and then the logic becomes much more straightforward.

The awkwardness for shoehorning streams into ranges I see is that the advancement (popFront) and the check for termination (empty) are decoupled, when in reality they are synced for a stream. This REQUIRES a sticky bit for popFront to communicate with empty on whether it is EOF or not.

Even a single byte buffer is not enough, you need a bool to indicate the stream is done.

-Steve

Reply via email to