std.v2020.algorithm etc[ WAS: Is run.d going to be expand for runtime and the phobos library?]

Steven Schveighoffer schveiguy at gmail.com
Sat Jun 20 20:17:29 UTC 2020


On 6/20/20 3:23 PM, Jon Degenhardt wrote:
> On Saturday, 20 June 2020 at 18:26:43 UTC, Steven Schveighoffer wrote:
>> But the larger point is that true input-only ranges are rare. The only 
>> problem is for classes, since you cannot invoke a copy constructor on 
>> those.
> 
> Interesting discussion. Could you expand on this comment? Several people 
> have mentioned this.

There are a few "base" ranges, like arrays, and data structure ranges. 
The one common true "input-only" range is a stream-based range (like 
File.byLine).

Other than that, wrapping ranges should implement the primitives that 
their dependencies do.

I'd say arrays are the most common range, and used for almost 
everything. Even with file streams, most of the time, you don't use the 
stream as a range, but use algorithms on the buffered data (which is an 
array).

An input range is generally useful in foreach, and almost nothing else.

> 
> I write my own input ranges somewhat regularly. I've never had the need 
> to make them forward ranges. However, the typical reason for creating a 
> range is because I have application specific data that I want to iterate 
> over (and usually construct) lazily. Input ranges are very convenient 
> way to do this. I do end up making many of them reference ranges though.

Many people do not bother adding ".save" because it's an extra thing, 
and copying works fine even if you don't declare save.

> 
> So, I'm wondering if its really that input-only ranges are rare, or if 
> it's that the number of algorithms that can be used on input-only ranges 
> is small. Or perhaps I'm not quite grokking the distinction between a 
> "true" input-only range and one that satisfies isInputRange, but none of 
> the other range primitive tests.

An input range cannot be (correctly) iterated more than once, even if 
you make copies of it.

-Steve


More information about the Digitalmars-d mailing list