How made my to!MyStruct

Jonathan M Davis jmdavisProg at gmx.com
Sat Jun 25 15:32:40 PDT 2011


On 2011-06-25 14:45, Jesse Phillips wrote:
> Zardoz Wrote:
> > Hi. I made a parametrized struct, a Vector, and I'm trying to make to!
> > work to make conversion between Vectors with different parametrized
> > type.
> 
> You should be able to override opCast and have it work with std.to, or I
> believe that is intended to work.

Nope. It won't work. It'll probably work with the next release, but it won't 
work right now. You can use std.conv.to instead of a cost for converting 
between derived objects; you can use it to convert an object to a string using 
its toString function; and if you have a to function on your struct or class 
which converts to a primitive type, you can use that with std.conv.to. But you 
can't currently convert between two unrelated objects using std.conv.to, even 
if they have the appropriate opCasts or constructors. That should change soon, 
but for now, we're out of luck.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list