Advertisement
Guest User

Untitled

a guest
Feb 24th, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.78 KB | None | 0 0
  1. struct io { import std.stdio; }
  2.  
  3. struct Bind(Args...)
  4. {
  5.     Args args;
  6.    
  7.     this(Args args)
  8.     {
  9.         assert(args.length > 0);
  10.         this.args = args;
  11.     }
  12.    
  13.     auto opCall()
  14.     {
  15.         auto func = args[0];
  16.        
  17.         static if(args.length > 1)
  18.             return func(args[1..$]);
  19.         else
  20.             return func();
  21.     }
  22. }
  23.  
  24. auto bind(FunctionType, Args...)(FunctionType func, Args args)
  25. {
  26.     return Bind!(FunctionType, Args)(func, args);
  27. }
  28.  
  29. auto bind(FunctionType)(FunctionType func)
  30. {
  31.     return Bind!(FunctionType)(func);
  32. }
  33.  
  34. void callme()
  35. {
  36.     io.writeln("called");
  37. }
  38.  
  39. void callmetoo(string stuff)
  40. {
  41.     io.writeln("called with ", stuff);
  42. }
  43.  
  44. void main()
  45. {
  46.     bind(&callme)();
  47.     bind(&callmetoo, "things")();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement