Semantics of toString
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Nov 10 15:49:54 PST 2009
Don wrote:
> Lutger wrote:
>> Don wrote:
>> ...
>>> There is a definite use for such as thing. But the existing toString()
>>> is much, much worse than useless. People think you can do something with
>>> it, but you can't.
>>> eg, people have asked for BigInt to support toString(). That is an
>>> over-my-dead-body.
>>
>> Since you are in the know and probably the biggest toString() hater
>> around: are there plans (or rejections thereof) to change toString()
>> before D2 turns gold? Seems to me it could break quite some code.
>
>
> I'm hoping someone will come up with a design.
>
> Straw man:
>
> void toString(void delegate(const(char)[]) sink, string fmt) {
>
> // fmt holds the format string from writefln/formatln.
> // call sink() to print partial results.
>
> }
I think the best option for toString is to take an output range and
write to it. (The sink is a simplified range.)
Andrei
More information about the Digitalmars-d
mailing list