[Issue 4266] add support for structs in std.format.doFormat

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 3 14:51:04 PDT 2010


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



--- Comment #2 from Trass3r <mrmocool at gmx.de> 2010-06-03 14:51:03 PDT ---
add this branch (+ import std.traits;)

else static if (isSomeString!(typeof(t))) // enclose a string in ""
    res ~= `"` ~ t ~ `"`;


and it nearly matches the C struct intialization style (except for pointers,
then you need to remove the first branch):


struct S
{
    int a;
    S2* p;

    S2 adad;
}

struct S2
{
    byte[4] aaaa = [0,1,2,3];
    string ddd = "asd";
}

void main()
{
    S2 sss = S2([5,4,5,4], "foo");
    S s = S(2, &sss);
    write(myformat(s));
}


gives:
{a:2, p:{aaaa:[5,4,5,4], ddd:"foo"}, adad:{aaaa:[0,1,2,3], ddd:"asd"}}

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