In the code snippet below should have @property. Otherwise, we get the result this:
>40
NP!(Foo!int)(opps!)
NP!(Foo!int)(opps!)
struct NP(V) {
private V payload;
this(V x)
{
payload = x;
}
alias opCall this;
@property: // <-- should be here
auto opCall() inout // ditto
{
return payload.value;
}
auto opCall(T)(T x)
{
return payload.value = x;
}
}
class Foo(T)
{
private T value;
NP!Foo wrapper;
this()
{
wrapper = NP!Foo(this);
}
override string toString()
{
return "opps!";
}
}
import std.stdio;
void main()
{
auto foo = new Foo!int;
foo.value = 40;
foo.value.writeln; // 40
foo.wrapper.writeln; // 40
foo.wrapper = 41;
foo.wrapper.writeln; // 41
}
SDB@79