Function pointer argument to function template

Oskar Linde oskar.lindeREM at OVEgmail.com
Wed May 31 08:45:02 PDT 2006


Tom S skrev:
> Daniel Keep wrote:
>> Actually, it's quite simple, if utterly evil.  It involves abusing IFTI
>> in the most gruesome manner imaginable...
>>
>> Detecting the number of arguments looks like this:
>>
>> ( ... )
>>
> 
> Neat !! I didn't realize IFTI could do that :D

I agree! But how can you call something this beautiful evil? :)

>> Thankfully, I have a nifty little Python script that saves me having to
>> actually *type* all that out.  I give it a maximum number of arguments,
>> and it goes off and generates the template for me.  Evil was never so 
>> easy!
> 
> Hehehe, I use it as well for other sorts of stuff, where I have to 
> generate lots of such code that would be handled by variadic templates 
> if we had them ;)

I think you can manage this without needing to resort to autogenerated 
code by using a generic variadic template list generator. There will 
still be a hard-coded limit in the maximum number of function arguments 
though.

> How about taking it a step further and doing something like:
> 
> ----
> import std.stdio;
> 
> struct FuncMeta(int NumArgs, Ret, T0=void, T1=void /+, and, so, on+/) {
>     alias FuncMeta Meta;
> 
>     static const int    numArgs = NumArgs;
>     alias    Ret            RetType;
>     alias    T0            Arg0Type;    // these might use static if as 
> well
>     alias    T1            Arg1Type;
>     /+
>     ... and so on
>     +/
> }

[snip the rest]

Marvelous! this will be very useful for me in a number of places.

/Oskar



More information about the Digitalmars-d mailing list