Why does toString() exist? It seems useless.

Christopher Wright dhasenan at gmail.com
Mon Aug 18 20:09:00 PDT 2008


Don wrote:
> I cannot understand the rationale for a toString() member function which 
> doesn't support formatting.

Nothing similar exists in Tango because, for structs, it requires 
compiler support.

In Tango, you can specify formatting for a particular type by 
subclassing Layout and overriding munge. Or rather, you could, except 
munge is private. Relevant ticket: 
http://dsource.org/projects/tango/ticket/1247

On the other hand, I've only ever used toString for debug output, using 
external formatters for anything with user-visible results. Again, if 
Layout.munge were not private, you could add external formatters easily.

This helps you not at all when using Phobos.



More information about the Digitalmars-d-learn mailing list