Advertisement
WeltEnSTurm

Untitled

Jun 14th, 2018
3,414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.67 KB | None | 0 0
  1. auto bindNames(alias fn)() if(isCallable!fn) {
  2.     class Wrapper {
  3.        
  4.         Parameters!fn parameterStorage;
  5.  
  6.         this(){
  7.             parameterStorage = ParameterDefaults!fn;
  8.         }
  9.  
  10.         static foreach(i, name; ParameterIdentifierTuple!fn){
  11.             mixin("auto " ~ name ~ "(Parameters!fn[i] value){ parameterStorage[i] = value; return this; }");
  12.             static if(is(Parameters!fn[i] == bool)){
  13.                 mixin("auto " ~ name ~ "(){ parameterStorage[i] = !parameterStorage[i]; return this; }");
  14.             }
  15.         }
  16.  
  17.         auto opCall(){
  18.             return fn(parameterStorage);
  19.         }
  20.  
  21.     }
  22.  
  23.     return new Wrapper;
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement