T opImplCast(T)() so we can add @disable to it?

Sjoerd Nijboer sjoerdnijboer at gmail.com
Thu May 24 06:42:51 UTC 2018


On Thursday, 24 May 2018 at 01:39:56 UTC, Jonathan M Davis wrote:
> If you don't want an implict cast, then why did you declare an 
> alias this?

Because I wanted an inconvertible type which was exactly like the 
int in the example but didn't want the implicit cast.

> That's the whole point of alias this. If you want implicit 
> conversions, you use alias this. If you don't, you don't use 
> alias this. I don't understand why it would ever make sense to 
> declare an implicit conversion and then disable it.

I think it doesn't make sense to allow us to have any influence 
on implicit casts. I don't think they should only be existant for 
primitive types.
What if you had a struct with two ints and you coulc convert it 
with an implicit cast into a different struct with two other 
ints? For me it makes sense to want an implicit cast there.

> Also, if you think that
>
> Foo foo = 5;
>
> is using an implicit cast, you're wrong. That's just calling 
> the constructor

I know, but 'writeln(foo)' compiles and runs but 
'writeln(cast(int) foo)' does not



More information about the Digitalmars-d mailing list