First Draft: cast(ref T)... as shorthand for *cast(T*)&...
Dom DiSc
dominikus at scherkl.de
Wed Feb 5 22:51:28 UTC 2025
On Wednesday, 5 February 2025 at 16:53:11 UTC, Paul Backus wrote:
> 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)`.
But it works for all types _that provide a constructor for the
source type_.
E.g. if Object provides a "this(const MyClass x)" or a
"this(T)(const T x) if(is(Unqual!T==MyClass))".
But this no different from the explicit cast, for which to work,
the source type (MyClass) has to provide a "opCast(T)()
if(is(Unqual!T==Object))".
So explicit cast works for all types that I want it to work with.
Implicit cast works only for custom types, but _not_ for the
buildin types :-(
More information about the dip.development
mailing list