DIP9 -- Redo toString API

Jacob Carlborg doob at me.com
Sun Nov 21 12:37:21 PST 2010


On 2010-11-21 17:28, Pelle Månsson wrote:
> On 11/21/2010 03:17 PM, spir wrote:
>> No, just use toString. As said above, I don't want to writeTo, I want
>> the string; and be free to do whatever I want to with it. Being only
>> able to write is... (rather censure).
>
> I... don't think you understand what writeTo is supposed to do.
>
> Inside to!string, it would be something like this:
>
> string s;
> arg.writeTo((const(char)[] data) { s ~= data; });
> return s;

Why can't toString do the same ?

> There, you got the string. It will even be in a function for you, so
> you'll never have to write that piece of code. If you ever need the
> string of an object, you just write to!string(obj). No functionality
> lost, ever, at all.
>
> However, writeln can do this:
>
> foreach (arg; args) {
> arg.writeTo((const(char)[] data) { outputbuffer.put(data); })
> }
>
> thereby removing the need to store the string, and the extra allocations.
>
> This design is much cleaner than the current strategy, and also more
> flexible.


-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list