xxxxxxxxxx
struct Foo(bool val)
{
private int payload;
static if (val == true)
{
void opAssign(int x)
{
payload = x;
}
}
else
{
void opAssign(int x);
}
}
import std.stdio : writeln;
void main()
{
auto x = Foo!true(1);
writeln(x); //prints Foo!true(1)
x = 2;
writeln(x); //prints Foo!true(2)
auto y = cast(Foo!false)x;
writeln(y); //pritns Foo!false(2)
//y = 3; //error not callable because it is disabled
}