Explicit implicit conversions
Quirin Schroll
qs.il.paperinik at gmail.com
Thu Feb 6 14:45:43 UTC 2025
On Thursday, 6 February 2025 at 03:03:05 UTC, Paul Backus wrote:
> On Thursday, 6 February 2025 at 02:32:54 UTC, Quirin Schroll
> wrote:
>> The idea is to allow, e.g. `Type(expression)` evaluate to
>> `expression` with a static type of `Type`.
>
> Unfortunately this syntax conflicts with constructors and
> `static opCall`, so it is probably a non-starter.
>
>> Of course, that lowering can be provided by a function
>> template:
>> ```d
>> auto ref R implicitCast(R, T)(auto ref T x) => x;
>> ```
>> The main issue with that is that it’s much wordier.
>
> Do we expect this to be used often enough that its length will
> be a big deal?
The deal is that something that’s that trivial shouldn’t require
a workaround, not even an easy one. It would have to be in
object.d to be easily used, otherwise I’d rather two-line it with
a local variable than two-line it with an `import` statement.
Really, there’s almost no benefit anymore if you have to import:
```d
import std.conv : implicitCast; // meh
f(x.implicitCast!R);
```
More information about the dip.ideas
mailing list