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

2015-06-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3189

Andrei Alexandrescu  changed:

   What|Removed |Added

Version|future  |D2

--


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

2009-08-28 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3189


Andrei Alexandrescu  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution||FIXED




--- Comment #1 from Andrei Alexandrescu   2009-08-28 
08:28:09 PDT ---
Ok. I implemented this:

/**
Object-_to-non-object conversions look for a method "to" of the source
object.

Example:

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

unittest
{
auto d = new Date;
auto ts = to!long(d); // same as d.to!long()
}

 */
T to(T, S)(S value) if (is(S : Object) && !is(T : Object) && !isSomeString!T
&& is(typeof(S.init.to!(T)()) : T))
{
return value.to!T();
}

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


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

2009-07-19 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3189


Andrei Alexandrescu  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED




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