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

Paul Backus snarwin at gmail.com
Wed Feb 5 16:53:11 UTC 2025


On Monday, 27 January 2025 at 18:10:07 UTC, Quirin Schroll wrote:
> Being able to request an implicit conversion is important when 
> a language has type inference. There are situations in which 
> you don’t want to truncate, but the type something has isn’t 
> the type it needs to be. `ushort(…)` is an explicit request for 
> an implicit cast.
>
> If you made `ushort(…)` an explicit request for a truncating 
> cast, how do I do an explicit request for an implicit cast?

The problem with using the syntax `ushort(...)` to request an 
implicit cast is that it *only* works for built-in primitive 
types. If I want to request an implicit cast from, say, `MyClass` 
to `Object`, I cannot do it by writing `Object(myClassInstance)`.

The solution here is to have a general method of requesting an 
implicit cast that works for *all* types. Perhaps a library 
function like `implicitCast!T`.


More information about the dip.development mailing list