[Issue 2287] New: to!(string)(struct) should work if struct has	toString() function
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sat Aug 16 16:45:26 PDT 2008
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=2287
           Summary: to!(string)(struct) should work if struct has toString()
                    function
           Product: D
           Version: 2.018
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: dsimcha at yahoo.com
import std.stdio, std.conv;
struct Foo {
    string toString() {
        return "test";
    }
}
void main() {
    Foo test;
    //Doesn't work.  std.conv unaware of foo.toString().
    writefln(to!(string)(test));
}
Obviously, this is a very simplified test case, but when writing generic code,
it can become a legitimate issue.  Also note that the following test case,
which just changes Foo to a class, actually works.
import std.stdio, std.conv;
class Foo {
    this(){}
    string toString() {
        return "test";
    }
}
void main() {
    Foo test = new Foo;
    writefln(to!(string)(test));
}
I've found the bug and the fix is a dead simple two-liner.  I'll attach the
diffs against conv.d.
-- 
    
    
More information about the Digitalmars-d-bugs
mailing list