First Draft: cast(ref T)... as shorthand for *cast(T*)&...

Dom DiSc dominikus at scherkl.de
Thu Jan 23 19:08:16 UTC 2025


On Thursday, 23 January 2025 at 01:56:32 UTC, Quirin Schroll 
wrote:

> `cast` should only ever do `@safe` casts, and be required for 
> stuff like `cast(ushort) myInt`.

For this, I wish ushort(myInt) would work. This would safe a LOT 
of unneccessary text and keep cast() for the more dangerous 
things.

But at the moment the compiler rejects that: "cannot implicitly 
cast myInt of type int to ushort". I would never consider 
ushort(x) "implicit". It really doesn't get any more explicit 
than this :-(

Allowing explicitly calling the constructor of a smaller type to 
truncate values could easily get allowed without breaking any 
existing code.
Especially because working with small types requires this cast 
over and over because every operation extends them to int.


More information about the dip.development mailing list