[phobos] toString (was: BigInt from Tango)

Lars Tandle Kyllingstad lars at kyllingen.net
Fri Apr 9 06:38:36 PDT 2010


Andrei Alexandrescu wrote:
> On 03/18/2010 10:46 PM, Don Clugston wrote:
>> (2)  Syntax for conversion to string is undecided. Strawman:
>>
>>   void toString(void delegate(const(char)[]) sink, string format);
>>
>> [...]
>>
>> Eventually, whatever is chosen will require some changes to
>> std.format, but I'd just like to get a reasonable first cut for the
>> initial release.
> 
> That's fine; we need to look again at std.format anyway.


Since Complex needs a toString() function as well, I am wondering:  Has 
the above been decided on as the standard for to-string conversion?

I'm asking because the newest part of std.format seems to be 
formattedWrite(), which writes to an output range.  Thus, an alternative 
would be

   void toString(OutputRange writer, string format);

IMO this seems more flexible, since the sink delegate solution is easily 
implemented as a trivial output range.  You can't necessarily do it the 
other way around (for instance, it requires quite a bit of typing if you 
just want toString to fill a buffer array).

Whatever it is, there really should be a standard signature, so that 
library and user types may work seamlessly with the writef*(), format() 
and to!string() functions.

-Lars


More information about the phobos mailing list