T opImplCast(T)() so we can add @disable to it?
Manu
turkeyman at gmail.com
Thu May 24 00:53:00 UTC 2018
On 23 May 2018 at 17:30, Sjoerd Nijboer via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> While tinkering with some code I eventually found that the following didn't
> do as I expected
>
> import std.conv;
> import std.stdio;
>
> void main()
> {
> Foo foo = 5;
> writeln(foo);
> }
>
> struct Foo{
> int i;
> alias i this;
> @disable T opCast(T)();
> this(int j)
> {i =j;}
> }
>
> If the cast in the example is implict this code compiles and executes.
> If the cast is explicit it doesn't.
> Is there a plan to expose something like 'opImplCast()()' so I can @disable
> it for some types where I absolutely don't want any accidental type
> conversions?
> Shouldn't this just be a feature of D?
I would REALLY love a way to implement an implicit cast that wasn't
`alias this` based... for reasons that are NOT to @disable it :P
More information about the Digitalmars-d
mailing list