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

Sjoerd Nijboer sjoerdnijboer at gmail.com
Thu May 24 00:30:03 UTC 2018


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?


More information about the Digitalmars-d mailing list