How to Distinguish between a Lambda and a Function Template at Compile Time

Meta jared771 at gmail.com
Wed Mar 26 17:56:13 PDT 2014


Is this a safe way to distinguish between function literals and 
function literal templates at compile time?

import std.functional;
import std.traits;

template makeFunAlias(alias F)
if (isSomeFunction!(typeof(F)) || is(typeof(F) == void))
{
	static if (is(typeof(F) == void))
	{
		alias makeFunAlias = unaryFun!(F!char);
	}
	else
	{
		alias makeFunAlias = unaryFun!F;
	}	
}

void main()
{
	alias test1 = makeFunAlias!((char c) => c);
	alias test2 = makeFunAlias!(function(char c) => c);
	alias test3 = makeFunAlias!(c => c);
}


More information about the Digitalmars-d-learn mailing list