Efficient outputting of to-string conversions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Feb 7 16:25:12 PST 2011


On 2/7/11 5:38 PM, Tomek Sowiński wrote:
> Jonathan M Davis napisał:
>
>> On Monday 07 February 2011 13:10:09 Tomek Sowiński wrote:
>>> Looks like std.conv.to always allocates behind the scenes. It's a shame as
>>> the returned string is immediately processed and discarded in my XML
>>> writer. Are there plans to include a custom output variant, e.g.
>>> to!string(7, outputRange)?
>>
>> http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP9
>
> I know about Steven's proposal but it applies only to user types not primitives. Either way std.conv.to would need a buffered output range as integers are written from the right. Any chance for an abstraction analogous to buffered input ranges discussed recently?

Generally I found it more difficult to define a solid output buffer 
abstraction. This is a great motivating example though.

To my surprise, an API of the same form seems to be what the doctor 
prescribed. Here's a semi-formal definition:

A buffered output range R is defined as such:

R.front returns the currently uncommitted buffer of type T[]

R.moreFront(n) makes n more elements available for writing

R.commitFront(n) writes the first n elements in front()

R.flushFront() writes the buffer currently held in front() and makes 
another buffer available (initially empty).


Andrei



More information about the Digitalmars-d mailing list