How to obtain certain traits of delegates returned by functions in template constraints?

TheFlyingFiddle kurtyan at student.chalmers.se
Sun Dec 15 09:20:03 PST 2013


On Sunday, 15 December 2013 at 10:44:38 UTC, Jacob Carlborg wrote:
> Hmm, there might be a way to strip all the attributes of a 
> function.

template strip(T) if(is(T == delegate))
{
     alias stripped = ReturnType!T delegate(ParameterTypeTuple!T);
}


template strip(T) if(is(T == function))
{
     alias stripped = ReturnType!T function(ParameterTypeTuple!T);
}

unittest
{
	alias a = void delegate(int) nothrow pure const;
	alias b = void delegate(int);
	static assert(is(stripped!a == stripped!b));
}

This should do the trick.


More information about the Digitalmars-d-learn mailing list