Casts and conversions done right

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Thu Jul 23 01:52:10 PDT 2009


Daniel Keep wrote:
> Lars T. Kyllingstad wrote:
>> Daniel Keep wrote:
>>> ...
>>>
>>> We could probably write another template called reinterpret!T or
>>> recast!T or something that explicitly takes a collection of bits and
>>> reinterprets them as another type (ie: the *cast(int*)&pi case).
>>
>> Wouldn't this by necessity have to be a built-in feature of the language?
> 
> Why would it?
> 
> ref T recast(T,U)(ref U v) if( T.sizeof <= U.sizeof )
> {
>     return *cast(T*)&v;
> }
> 
> Or something similar should be possible.

Ah, I misunderstood your "lock cast(T) away in a box and electrocute the 
lid" comment to mean that the current cast(T) should be entirely removed 
from the language. (Which is something I personally wouldn't be opposed to.)

-Lars



More information about the Digitalmars-d mailing list