www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Extracting function param types using variadic templates

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
Hmm.

I can do this:

void variadic(T...)(T args){}
variadic(1, 2, 3);

This:

void returnType(T)(T delegate() dg){}

returnType(delegate int(){ return 0; });

Even this:

void returnAndArg(T, U)(T delegate(U) dg){}
returnAndArg(delegate int(bool b){ return 0; });

But not:

void returnAndArgs(T, U...)(T delegate(U) dg){}
returnAndArgs(delegate int(bool b){ return 0; });

!

One can dream, no?

Is there maybe some other way to get at the parameter types of a function as 
a tuple, using variadic magic? 
Nov 03 2006
parent reply Tom S <h3r3tic remove.mat.uni.torun.pl> writes:
Jarrett Billingsley wrote:
 Is there maybe some other way to get at the parameter types of a function as 
 a tuple, using variadic magic? 

How about this stuff: http://www.dsource.org/projects/pyd/browser/trunk/infrastructure/meta ?
Nov 03 2006
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Tom S" <h3r3tic remove.mat.uni.torun.pl> wrote in message 
news:eigch3$ilf$1 digitaldaemon.com...
 Jarrett Billingsley wrote:
 Is there maybe some other way to get at the parameter types of a function 
 as a tuple, using variadic magic?

How about this stuff: http://www.dsource.org/projects/pyd/browser/trunk/infrastructure/meta ?

But that's basically using my third example, i.e. void returnAndArg(T, U)(T delegate(U) dg){} returnAndArg(delegate int(bool b){ return 0; }); But with many specializations of the template, one for each number of params. The point of using variadic templates is removing the need to manually create a specialization for each number of things you want in the typelist. With the automatic tuple deduction that I wish existed, the FuncMeta.d module would become about 80 lines of code, and it would be able to support any number of arguments.
Nov 03 2006
parent reply Kirk McDonald <kirklin.mcdonald gmail.com> writes:
Jarrett Billingsley wrote:
 "Tom S" <h3r3tic remove.mat.uni.torun.pl> wrote in message 
 news:eigch3$ilf$1 digitaldaemon.com...
 Jarrett Billingsley wrote:
 Is there maybe some other way to get at the parameter types of a function 
 as a tuple, using variadic magic?

http://www.dsource.org/projects/pyd/browser/trunk/infrastructure/meta ?

But that's basically using my third example, i.e. void returnAndArg(T, U)(T delegate(U) dg){} returnAndArg(delegate int(bool b){ return 0; }); But with many specializations of the template, one for each number of params. The point of using variadic templates is removing the need to manually create a specialization for each number of things you want in the typelist. With the automatic tuple deduction that I wish existed, the FuncMeta.d module would become about 80 lines of code, and it would be able to support any number of arguments.

This was approximately the first thing I tried doing with variadic templates. I was very saddened to see that it doesn't work. -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.org
Nov 03 2006
parent Walter Bright <newshound digitalmars.com> writes:
Kirk McDonald wrote:
 This was approximately the first thing I tried doing with variadic 
 templates. I was very saddened to see that it doesn't work.

I agree, and I'll break out the hammer & tongs and see if I can make it work.
Nov 03 2006