DIP9 -- Redo toString API

Pelle Månsson pelle.mansson at gmail.com
Sun Nov 21 08:28:09 PST 2010


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;

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.


More information about the Digitalmars-d mailing list