Input ranges

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 20 00:46:52 PDT 2015


On Sunday, 19 April 2015 at 23:49:08 UTC, anonymous wrote:
> On Sunday, 19 April 2015 at 21:42:23 UTC, Ulrich Küttler wrote:
>> groupBy is a nice example as it laboriously adds reference 
>> semantics to forward ranges but assumes input ranges to posses 
>> reference semantics by themselves.
>
> All ranges are input ranges, though. Input ranges are the least 
> specialised category. I think it's a mistake to assume/require 
> anything only for input ranges that are not forward ranges.

Yes and no. It is reasonable to provide special implementations 
for ranges that are just input ranges. This is what groupBy does. 
The user gets a function that works with all kinds of ranges.

>
> I guess we could require reference semantics for all input 
> ranges (including forward ranges and higher-ups). That would be 
> a rather clean way out of this mess. But it would be a major 
> effort. And I guess it would hurt performance, maybe a lot.

Definitely, general reference semantics would solve a ton of 
difficulty. However, this would not be D anymore.

This seems to be the catch: For optimal performance memory layout 
is important. You cannot hide it behind an interface.

>
>> At this point the solution in byLineCopy feels ad hoc.
>
> I think byLineCopy solves a different problem. ByLine already 
> has this:
> https://github.com/D-Programming-Language/phobos/blob/v2.067.0/std/stdio.d#L1592-L1598

The same indirection in byLineCopy. This is what I was referring 
to:

https://github.com/D-Programming-Language/phobos/blob/v2.067.0/std/stdio.d#L1783-L1789

Whoever did that knew very well what is going on.


More information about the Digitalmars-d-learn mailing list