Bug 7881 – std.string.format does not support structs with no toString

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-09T16:02:00Z
Last change time
2013-01-24T16:19:44Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2012-04-09T16:02:18Z
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 .. $]); }
Comment #1 by k.hara.pg — 2012-04-09T21:38:54Z
This issue is almost a dup of 4532. *** This issue has been marked as a duplicate of issue 4532 ***
Comment #2 by andrej.mitrovich — 2013-01-24T16:19:44Z
I'm making as WORKSFORME instead because it's fixed, the other issue is still opened.