xxxxxxxxxx
import std.stdio;
import std.variant : Variant;
struct var {
private Variant[string] values;
Variant opDispatch(string name)() const {
return values[name];
}
void opDispatch(string name, T)(T val) {
values[name] = val;
}
}
void main()
{
var test;
// Normal flow
test.foo = "test";
test.bar = 50;
writeln("test.foo = ", test.foo);
writeln("test.bar = ", test.bar);
// Error flow
with (test) {
foobar = 3.14;
}
writeln(test.foobar);
}