[phobos] Would you find a ByRef range useful?

Lars Tandle Kyllingstad lars at kyllingen.net
Mon Jun 6 03:08:28 PDT 2011


On Thu, 2011-05-19 at 17:34 -0500, Andrei Alexandrescu wrote:
> On 5/19/11 5:09 PM, Lars Tandle Kyllingstad wrote:
> > It definitely needs to be fleshed out a bit, yes.  Right now it's
> > sufficient for my uses, however, so I just thought I'd gauge the
> > interest before making any improvements.
> 
> In fact byRef is a fairly general tool not limited to ranges. It could 
> work by storing the address and implementing opDispatch to forward 
> appropriately.

I agree, but it would still need to be specialised for ranges.   If
nothing else, the enum-ness of empty needs to be propagated.  Also,
perhaps save() should *not* be propagated -- see my reply to Robert.


> We need more evidence of its utility before making a decision.

Basically, it makes the opposite guarantee of save().  It has always
bothered me that if you call a function on a range,

    doStuffWith(range);

there is a priori no way to tell whether it is going to consume the
original range, or whether it will iterate over a copy of the range.  It
depends on the range, and it depends on the function.  While

    doStuffWith(range.save);

guarantees the latter, we need something like

    doStuffWith(byRef(range));

to guarantee the former.  Currently, the only way to do this is to write

    doStuffWith(inputRangeObject(range));

which is massive overkill if all you want is for the original range to
be consumed.

-Lars



More information about the phobos mailing list