Function traits at compile time

BCS BCS at pathlink.com
Mon Jun 12 10:50:28 PDT 2006


Victor Nakoryakov wrote:
> Hi all,
> 
> Consider code:
> 
> class MyClass(StructT)
> {
> ...
> }
> 
> I know, that StructT has a function `foo` in it, but I don't know number 
> of parameters and their types, of course. Does anybody knows a way to 
> extract types to use them in `static if ( is(...) )` statements?
> 
> 
this kida-sorta works. I have to run so I'll post it as is.

<code>
import std.stdio;

template isType(alias match, alias what)
{
	static if(is(typeof(match) == typeof(what)))
		const bool isType = true;
	else
		const bool isType = false;
}

int foo();
int bar(int);

void main()
{
	writef(isType!(function int(){}, function int(){}),\n);
}
</code>



More information about the Digitalmars-d mailing list