Function traits at compile time

Daniel Keep daniel.keep.lists at gmail.com
Mon Jun 12 08:31:50 PDT 2006


Victor Nakoryakov wrote:
> Hi all,

Hi.

> 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?

Ok, this is ugly, and evil, evil hack, but it works.  The python script
that generated it is included if you need more and/or less arguments.

Some examples:

# NumberOfArgs!(&StructT.foo); // Number of arguments
# ReturnType!(&StructT.foo);   // Alias to return type
# ArgType!(&Struct.foo, n);    // Alias to type of 'n'th argument
#                              // (counting from 1).

Hope this helps :)

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ftype.zip
Type: application/octet-stream
Size: 2767 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20060613/55bef1ce/attachment.obj>


More information about the Digitalmars-d mailing list