Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 9th, 2012  |  syntax: D  |  size: 0.52 KB  |  views: 72  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. struct Animal {
  2.     int delegate(int) fly;
  3.     void delegate() crawl;
  4. }
  5.  
  6. // Use structs
  7. struct Bird {
  8.     Animal animal;
  9.     alias animal this;
  10.    
  11.     Wing[] wings;
  12.    
  13.     this()
  14.     {
  15.         animal.fly = &flyImpl;
  16.         anumal.crawl = &crawlImpl;
  17.     }
  18.    
  19.     int flyImpl(int) { return use(wings); }
  20.     void crawlImpl() { }
  21. }
  22.  
  23. // Use closures
  24.  
  25. Animal makeBird()
  26. {
  27.     Animal bird;
  28.     Wing wings;
  29.    
  30.     bird.fly = (int) { return use(wings); }
  31.     bird.crawl = () {};
  32.     return bird;
  33. }