delegate, template and alias

Heromyth bitworld at qq.com
Mon Dec 19 06:35:49 PST 2011


== Quote from Heromyth (bitworld at qq.com)'s article
> == Quote from Philippe Sigaud (philippe.sigaud at gmail.com)'s article
> > I suppose you do *not*want the commented line?
> I want to convert a delegate type define in C# to D's, as such:
>     public delegate void AsynchronousAction<T>(T argument, AsyncContinuation asyncContinuation);
>     public static void ForEachItemSequentially<T>(IEnumerable<T> items, AsyncContinuation asyncContinuation, AsynchronousAction<T> action)
>     {
>         ......
>     }

Woo, I got it.

template AsynchronousAction(T)
{
	alias void delegate(T argument) AsynchronousAction;
}

public class TestC
{
	int b = 3;

	//void test(T)(void delegate(T argument) func )
	void test(T)(AsynchronousAction!(T) func )
	{
		static if(is(T == string))
		func("It's me");
	}

	this(int x)
	{
		b = x;
	}
}


More information about the Digitalmars-d-learn mailing list