Thread overview
[Issue 7881] New: std.string.format does not support structs with no toString
Apr 09, 2012
Andrej Mitrovic
Apr 10, 2012
Kenji Hara
Jan 25, 2013
Andrej Mitrovic
April 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7881

           Summary: std.string.format does not support structs with no
                    toString
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-04-09 16:02:18 PDT ---
import std.string;
import std.stdio;

struct Foo
{
    string name;
}

void main()
{
    Foo foo;

    // ok
    writefln("%s", foo);

    // Can't convert test.Foo to string: "string toString()" not defined
    format("%s", foo);
}

I thought I was being clever when implementing this:
void printfln(string file = __FILE__, int line = __LINE__, T...)(T t)
{
    writefln("%s L %s - %s", file, line, format(t[0], t[1 .. $]));
}

It gives me a nice file+line when printing (great for debugging). Unfortunately
format() fails to work in numerous cases that writef has no issues with.

Anywho I can use this workaround:
void printfln(string file = __FILE__, int line = __LINE__, T...)(T t)
{
    writef("%s L %s - ", file, line);
    writefln(t[0], t[1 .. $]);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7881


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-04-09 21:38:54 PDT ---
This issue is almost a dup of 4532.

*** This issue has been marked as a duplicate of issue 4532 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 25, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=7881


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|DUPLICATE                   |WORKSFORME


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-24 16:19:44 PST ---
I'm making as WORKSFORME instead because it's fixed, the other issue is still opened.

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