How to distinguish a delegate from a function?

Oliver Dathe o.dathe at gmx.de
Sat Jul 12 18:38:36 PDT 2008


This works here:

template isCallableStatically(T)
{
	static if (is(T==function) || is(typeof(*T)==function))
		const bool isCallableStatically = true;
	else static if (is(T==delegate))
		const bool isCallableStatically = false;
	else static assert (false);
}

template isCallableStatically(alias T)
{
	const isCallableStatically = isCallableStatically!(typeof(&T));
}

void fn() {}

void main()
{
	void dg() {}

	static assert (isCallableStatically!(fn));
	static assert (!isCallableStatically!(dg));
	static assert (isCallableStatically!(typeof(&fn)));
	static assert (!isCallableStatically!(typeof(&dg)));
}



More information about the Digitalmars-d mailing list