GCs in the news
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 17 22:44:26 PDT 2014
On 7/17/2014 11:32 AM, Dicebot wrote:
> Plain algorithm ranges rarely need to allocate at all so those are somewhat
> irrelevant to the topic. What I am speaking about are variety of utility
> functions like this:
>
> S detab(S)(S s, size_t tabSize = 8)
> if (isSomeString!S)
>
> this allocates result string. Proper alternative:
>
> S detab(S)(ref S output, size_t tabSize = 8)
> if (isSomeString!S);
>
> plus
>
> void detab(S, OR)(OR output, size_t tab_Size = 8)
> if ( isSomeString!S
> && isSomeString!(ElementType!OR)
> )
That algorithm takes a string and writes to an output range. This is not very
composable. For example, what if one has an input range of chars, rather than a
string? And what if one wants to tack more processing on the end?
A better interface is the one used by the byChar, byWchar, and byDchar ranges
recently added to std.utf. Those accept an input range, and present an input
range as "output". They are very composable, and can be stuck in anywhere in a
character processing pipeline. They do no allocations, and are completely lazy.
The byChar algorithm in particular can serve as an outline for how to do a detab
algorithm, most of the code can be reused for that.
More information about the Digitalmars-d
mailing list