fork download
  1. import std.stdio;
  2.  
  3. class Foo
  4. {
  5. void xyz() { writeln("Xyz without arguments exists!"); }
  6.  
  7. void opDispatch(string name, T...)(T args)
  8. in
  9. {
  10. static assert (name == "foo" || name == "baz", "Invalid method called!");
  11. }
  12. body
  13. {
  14. writeln("Called method: ", name);
  15. foreach (i, arg; args) writefln("args[%d] == %s", i, arg);
  16. }
  17. }
  18.  
  19. void main()
  20. {
  21. Foo bar = new Foo();
  22. bar.baz();
  23. bar.xyz();
  24. bar.foo("hello", [5,10,15], 3.14f, ["foo":5, "bar":10], true);
  25. bar.asdasdasd();
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.d(10): Error: static assert  "Invalid method called!"
prog.d(25):        instantiated from here: opDispatch!("asdasdasd",)
stdout
Standard output is empty