[Issue 3189] `std.conv.to` : check for a custom `to` method in classes/structs
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 28 08:28:09 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3189
Andrei Alexandrescu <andrei at metalanguage.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #1 from Andrei Alexandrescu <andrei at metalanguage.com> 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: -------
More information about the Digitalmars-d-bugs
mailing list