algorithms that take ranges by reference

Philippe Sigaud philippe.sigaud at gmail.com
Thu Dec 31 12:43:26 PST 2009


On Thu, Dec 31, 2009 at 01:11, Andrei Alexandrescu <
SeeWebsiteForEmail at erdani.org> wrote:

> Kevin Bealer wrote:
>
>>
>>> It is becoming, however, increasingly clear that there are algorithms
>>> that could and should manipulate ranges by reference. They might take and
>>> return values, but it's just too messy to do so. (Cue music for the "improve
>>> built-in tuples choir.)
>>>
>>> Let me suggest one more function I've found very useful:
>>
>> bool readUntil(R1, R2, R3)(ref R1 input, R2 delim, ref R3 result)
>> {
>>  // Like findSkip, but returning intervening text.
>> }
>>
>
> You read my mind. I was thinking of something with "copy" in the name.
>
>
I find popFrontUntil / popFrontWhile to be quite useful myself.  Heck, I
even needed an 'exhaust' function once, that just takes a range (mostly, the
rest of a range inside an algorithm) and makes it empty. When writing these
by-ref funs, I take care to indicate quite clearly in the docs that they
modify the input range, because it's not  a common pattern in std.algorithm.

I like Michel's suggestion to use consume as a prefix. If Phobos goes for a
nested structure, you could put this consuming algorithms in a special
module for them. std.algorith.consume or somesuch.

 Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20091231/1610769d/attachment.html>


More information about the Digitalmars-d mailing list