"Adam D. Ruppe" <destructiona...@gmail.com> wrote in message news:bighgnfjujyisywpc...@forum.dlang.org... > > import std.variant; > struct Extendable { > Variant[string] properties; > Variant opDispatch(string name)() { > return properties[name]; > } > Variant opDispatch(string name, T)(T t) { > properties[name] = t; > return properties[name]; > } > } > > void main() { > auto a = Extendable(); > a.sweet = 10; > a.cool = { a.sweet = a.sweet + 1; } // could probably fix ++ too.. > // fails with std.variant but the language *could* do it > a.cool(); // exercise for the reader: maek this work! Gotta add > opCall. > } >
I'm compelled to make a slight tweak to that: import std.variant; struct Extendable { Variant[string] properties; Variant opDispatch(string name)() { return properties[name]; } Variant opDispatch(string name, T)(T t) { properties[name] = t; return properties[name]; } // Tweak Start void crystal() { this.wild = true; this.sweet = true; this.cool = true; } // Tweak End }