Ranges of char and wchar

via Digitalmars-d digitalmars-d at puremagic.com
Thu May 8 13:41:14 PDT 2014


On Thursday, 8 May 2014 at 18:21:32 UTC, H. S. Teoh via
Digitalmars-d wrote:
> I've thought about input ranges vs. output ranges for a bit.  I 
> think it
> doesn't make sense for functions that process data to take an 
> output
> range: output ranges are data sinks, and should only be used 
> for the
> endpoint of a data processing pipeline. Since the string 
> function
> doesn't know whether or not it's the last in a pipeline (only 
> the
> calling code can know this), it should return an input range. 
> If the
> user code wants to put the result into an output range, then it 
> should
> simply use std.algorithm.copy.

I agree with H. S. Teoh. Indeed, I was thinking of trying to
create an alternative version of std.format which returned an
InputRange, instead of taking an OutputRange. The benefit of this
becomes obvious when you want to use std.format() in your own
ranges, which currently impairs laziness, pipelining, avoiding
memory allocations, etc.


More information about the Digitalmars-d mailing list