Small Vectors Proposal

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Thu Feb 1 10:06:41 PST 2007


Deewiant wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Mikola Lysenko wrote:
>>> 3. Casting rules
>>>
>>> Vector types will obey the same casting rules as their base type
>>> within a single dimension.  It is not possible to use a cast to change
>>> the dimension of a vector.
>>>
>>> cast(float2)(int2(1, 2));    //ok
>>> cast(int)(float2(3, 4));    //error, int is not the same dimension as float2
>>> real3(a, b) + ireal(c, d);    //ok, type of expression is creal3
>> opCast. Yup, check that sucker too.
>>
> 
> I presume the original proposal would have allowed both cast(float2)(int2(1, 2))
> and cast(real2)(int2(1, 2)). Currently, however, we can have only one opCast per
> struct/class.
> 
> Is this a planned D 2.0 change I've missed, or how would this work?

It is a change that I personally think should be made. Walter devised 
the one cast per class rule out of caution when facing an issue known to 
be potentially disastrous. Generally, the "when in doubt, don't put it 
in" approach turned out to be a winner for D in general --- the "length" 
Chernobyl disaster notwithstanding :o).

As our grasping of the tradeoffs involved improves, the right choices 
will appear naturally. This is sort of what happened with opAssign.


Andrei



More information about the Digitalmars-d mailing list