Summary: std.string.format does not support structs with no
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from Andrej Mitrovic <> 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:
------- You are receiving this mail because: -------

Reply via email to