view dwt/dwthelper/Runnable.d @ 7:e831403a80a9

Add 'cast' to casts
author Frank Benoit <benoit@tionex.de>
date Wed, 27 Aug 2008 14:30:35 +0200
parents 380af2bdd8e5
children 30a762abda2a
line wrap: on
line source

/**
 * 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 _DgRunnableT(Dg,T...) : Runnable {

    alias ParameterTupleOf!cast(Dg) DgArgs;
    static assert( is(DgArgs == Tuple!cast(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);
    }
}

_DgRunnableT!(Dg,T) dgRunnable(Dg,T...)( Dg dg, T args ){
    return new _DgRunnableT!(Dg,T)(dg,args);
}