1 /** 2 * Authors: Frank Benoit <benoit@tionex.de> 3 */ 4 module java.lang.Runnable; 5 6 version(Tango){ 7 import tango.core.Tuple; 8 import tango.core.Traits; 9 } else { // Phobos 10 static import std.traits; 11 static import std.typetuple; 12 } 13 14 public interface Runnable { 15 16 public abstract void run(); 17 18 } 19 20 class _DgRunnableT(Dg,T...) : Runnable { 21 22 version(Tango){ 23 alias ParameterTupleOf!(Dg) DgArgs; 24 static assert( is(DgArgs == Tuple!(T)), 25 "Delegate args not correct: "~DgArgs.stringof~" vs "~T.stringof ); 26 } else { // Phobos 27 alias std.traits.ParameterTypeTuple!(Dg) DgArgs; 28 static assert( is(DgArgs == std.typetuple.TypeTuple!(T)), 29 "Delegate args not correct: "~DgArgs.stringof~" vs "~T.stringof ); 30 } 31 32 Dg dg; 33 T t; 34 35 private this( Dg dg, T t ){ 36 this.dg = dg; 37 static if( T.length > 0 ){ 38 this.t = t; 39 } 40 } 41 42 void run( ){ 43 dg(t); 44 } 45 } 46 47 _DgRunnableT!(Dg,T) dgRunnable(Dg,T...)( Dg dg, T args ){ 48 return new _DgRunnableT!(Dg,T)(dg,args); 49 }