[Issue 9872] New: format should print class fields

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 4 00:27:26 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9872

           Summary: format should print class fields
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-04-04 00:27:25 PDT ---
This is an unfortunate inconsistency:

import std.stdio;
import std.string;

struct S
{
    int x, y;
}

class C
{
    int x, y;
}

void main()
{
    auto s1 = format("%s", S());
    auto s2 = format("%s", new C());

    writeln(s1);  // S(0, 0)
    writeln(s2);  // test.C
}

It forces us to either always define a toString() method or call some custom
user-provided formatting function. format() should try to print the values of
the class fields if the toString method is not defined.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list