# HG changeset patch # User Frank Benoit # Date 1208370004 -7200 # Node ID 09234db163703b9a6c6d792093f841415d0b2eb1 # Parent 654b7d7cc33c344cb6a3093e852a8babb50e4c23 Delegate creator function dgIRunnable diff -r 654b7d7cc33c -r 09234db16370 dwt/dwthelper/Runnable.d --- a/dwt/dwthelper/Runnable.d Wed Apr 16 20:19:29 2008 +0200 +++ b/dwt/dwthelper/Runnable.d Wed Apr 16 20:20:04 2008 +0200 @@ -1,12 +1,39 @@ -/** +/** * Authors: Frank Benoit */ module dwt.dwthelper.Runnable; + +import tango.core.Tuple; +import tango.core.Traits; + public interface Runnable { public abstract void run(); } +class _DgIRunnableT(Dg,T...) : Runnable { + alias ParameterTupleOf!(Dg) DgArgs; + static assert( is(DgArgs == Tuple!(T)), + "Delegate args not correct" ); + + Dg dg; + T t; + + private this( Dg dg, T t ){ + this.dg = dg; + static if( T.length > 0 ){ + this.t = t; + } + } + + void run( ){ + dg(t); + } +} + +_DgIRunnableT!(Dg,T) dgIRunnable(Dg,T...)( Dg dg, T args ){ + return new _DgIRunnableT!(Dg,T)(dg,args); +} \ No newline at end of file