[Issue 3189] New: `std.conv.to` : check for a custom `to` method in classes/structs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 18 10:04:58 PDT 2009


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

           Summary: `std.conv.to` : check for a custom `to` method in
                    classes/structs
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: julien at onandon.be


Hello,

it would be nice if `std.conv.to` on class or struct could check if this class
or struct implements its own `to` method.

Something as :

           module Date;

                      class Date
                      {
                                 T to(T)() if(is(T == long))
                                 {
                                            return timestamp;
                                 }
                      }

           module std.conv;

                      T to(T, S)(S s) if (is(S : Object)
                      {
                                 static if(is(typeof(s.to!(T)())))
                                            return s.to!(T)();
                                 return /* whatever */;
                      }

           module test;

                      void main()
                      {
                                 assert(to!(long)(new Date) == 123124142324);
                      }

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