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

Reply via email to