Phobos for Review: std.buffer.scopebuffer

Jerry jlquinn at optonline.net
Fri Feb 7 13:05:43 PST 2014


"Lars T. Kyllingstad" <public at kyllingen.net> writes:

> On Friday, 7 February 2014 at 10:29:07 UTC, Walter Bright wrote:
> Ah, now I understand.  I misunderstood you -- I thought you meant that using
> ScopeBuffer to build the return array inside buildPath(), while retaining the
> function's API, would somehow improve its performance greatly.  But what
> you're saying is that you would change the signature as well, to something
> like this:
>
>   void buildPath(IR, OR)(IR segments, OR result)
>       if (isInputRange!IR && isOutputRange!(OR, char));
>
> I fully agree, then, and I see how ScopeBuffer would be extremely useful if
> more of Phobos' functions were written like this.  In the specific case of
> buildPath(), I've actually considered letting the user supply their own buffer
> in the form of an array, but this is of course a more general solution.

I'd suggest reversing the arguments:

  void buildPath(IR, OR)(OR result, IR segments)
      if (isInputRange!IR && isOutputRange!(OR, char));

That way you can use it as:

buffer.buildPath(p1, p2, ...);

It at least opens up chaining possibilities.



More information about the Digitalmars-d mailing list