How made my to!MyStruct

Zardoz luis.panadero at gmail.com
Sat Jun 25 16:07:57 PDT 2011


On Sat, 25 Jun 2011 15:32:40 -0700, Jonathan M Davis wrote:

> 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

Yep, I try with opCast and to! not works yet. At least, I can do now, 
things like :

auto v2d = Vector!(doble, 2) (1, 1);
auto v = cast(Vector!(float, 4)) v2d;
assert (v[0] == 1);
assert (v[1] == 1);
assert (v[2] == 0);
assert (v[3] == 0);

PD: Yep, I'm learning making a small lib to work with Vectors, 
Quaternions and squared Matrix...
-- 
Yep, I'm afraid that I have a blog : zardoz.es


More information about the Digitalmars-d-learn mailing list