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))

?


Andrei

Reply via email to