fork download
  1. import std.stdio;
  2.  
  3. class Foo
  4. {
  5. int[string] vals;
  6.  
  7. Foo opIndexAssign(int val, string key)
  8. {
  9. writefln("Got key %s", key);
  10. vals[key] = val;
  11. return this;
  12. }
  13. }
  14.  
  15. Foo foo;
  16.  
  17. void main()
  18. {
  19. foo = new Foo;
  20. foo["lol"] = 5;
  21. writefln("%d", foo.vals["lol"]);
  22. }
Success #stdin #stdout 0.01s 2120KB
stdin
Standard input is empty
stdout
Got key lol
5