protocol for using InputRanges

Walter Bright newshound2 at digitalmars.com
Thu Mar 27 14:24:11 PDT 2014


On 3/27/2014 2:13 PM, Steven Schveighoffer wrote:
> 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 range becomes the one element buffer in this case. It is completely workable.


> 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.

The range protocol is designed to work with streams. It's a giant fail if they 
do not, or if you want to create a separate, non-range universe to deal with 
streams.


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

Right. But empty for a stream still has to read. Just follow the protocol, and 
the range will work, even with streams.



More information about the Digitalmars-d mailing list