Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.54 KB | None | 0 0
  1. class Container {
  2.     Foo foo = void;
  3.    
  4.     this() {
  5.         foo = Foo();   
  6.     }
  7. }
  8.  
  9. struct Foo {
  10.     void bar() {
  11.         import std.stdio;
  12.         writeln("Foo.bar");
  13.     }
  14. }
  15.  
  16. struct FooBar {
  17.     void* origin;
  18.     void delegate() barFunc;
  19.     void delegate() caller;
  20.  
  21.     this(Foo* origin) {
  22.             this.origin = origin;
  23.             this.barFunc = &origin.bar;
  24.             barFunc = &callFunc!7;
  25.     }
  26.    
  27.     void call() {
  28.         caller();
  29.     }
  30.    
  31.     void callFunc(int foobared)() {
  32.         barFunc();
  33.     }
  34. }
  35.  
  36. void main() {
  37.     Container ctx = new Container;
  38.     FooBar foobar = FooBar(&ctx.foo);
  39.     foobar.call;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement