dmd 2.029 release

Georg Wrede georg.wrede at iki.fi
Thu Apr 23 06:59:39 PDT 2009


Andrei Alexandrescu wrote:
> Georg Wrede wrote:
>> Second, since we have cool stuff in D, like templates, boxing, and 
>> other advanced things, then compared to them, it should not be a big 
>> deal to have automatic creation of toString for structs and objects. 
>> (This could even be on-demand, i.e. unless called, the toString is not 
>> created for an object/struct.)
>>
>> Since the purpose of toString here is not Grand Style, it should 
>> suffice to just recursively print the struct with its possible 
>> substructs, etc.
>>
>> This would relieve the programmer from the entire extra work, and it 
>> would also make objects look tidyer in source code.
> 
> Did you know that this:
> 
> #!/home/andrei/bin/rdmd
> import std.conv, std.stdio;
> 
> struct S1
> {
>     int a = 42;
>     S2 b;
> }
> 
> struct S2
> {
>     int x = 4;
>     float y = 5.5;
> }
> 
> void main()
> {
>     writeln(to!string(S1()));
> }
> 
> prints this
> 
> S1(42, S2(4, 5.5))

Wow!

What if writeln would automatically call to!string for any object or struct?



More information about the Digitalmars-d-announce mailing list