Untitled
unknown
d
3 years ago
564 B
11
Indexable
import std.stdio;
import std.variant;
public class Blah {
private Variant[string] values;
alias values this;
this() {
this.x = 5;
}
@property
Variant opDispatch(string name)() const {
return values[name];
}
@property
void opDispatch(string name, T)(T val) {
values[name] = val;
}
void update() {
this.x = this.x + 1;
}
}
void main()
{
Blah blah = new Blah();
writeln(blah["x"]);
writeln(blah.x);
blah.update();
writeln(blah["x"]);
writeln(blah.x);
}
Editor is loading...