Mercurial > projects > dwt-linux
changeset 232:09234db16370
Delegate creator function dgIRunnable
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 16 Apr 2008 20:20:04 +0200 |
parents | 654b7d7cc33c |
children | 72c35686c8a1 |
files | dwt/dwthelper/Runnable.d |
diffstat | 1 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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 <benoit@tionex.de> */ 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