Dynamic language
F i L
witte2008 at gmail.com
Fri Mar 16 02:12:56 PDT 2012
Adam D. Ruppe wrote:
> 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.
> }
Alright I give up dammit! How do you use opCall() to make
a.cool() work?
More information about the Digitalmars-d
mailing list