www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Variable Template Args

reply "Craig Black" <cblack ara.com> writes:
I must praise D's templates.  They transcend C++ templates by an order of 
magnitude.  Much thanks to Walter and everyone who assisted him in making D's 
templates so darn cool.



I know this will not be a priority for 1.0.  I'm just thinking about future 
possibilities.  Looking at Oskar's tuple code spurred my thinking.  I wonder 
how difficult it would be to have an array of types as a template parameter. 
This would facilitate variable number of template arguments, an incredibly 
powerful template feature.  So instead of



 template MakeTuple(T1=Empty, T2=Empty, T3=Empty, T4=Empty,
                    T5=Empty, T6=Empty, T7=Empty, T8=Empty) {
   static if (is(T1 == Empty))
     alias Empty MakeTuple;
   else
     alias Tuple!(T1,MakeTuple!(T2,T3,T4,T5,T6,T7,T8)) MakeTuple;
 }



we could have something like



 template MakeTuple(Types[] ...) {
   static if (is(Types[0] == Empty))
     alias Empty MakeTuple;
   else
     alias Tuple!(Types[0],MakeTuple!(Types[1..$-1])) MakeTuple;
 }



Probably only Walter would know how hard something like this would be to 
implement, but it would be wickedly powerful.



BTW, it's not a big deal, but why is "is" required to compare types.  Does 
it make it easier for the compiler to parse or something?  Otherwise, I 
don't see why it's necessary.



-Craig
Feb 09 2006
parent "Walter Bright" <newshound digitalmars.com> writes:
"Craig Black" <cblack ara.com> wrote in message 
news:dsgbon$2e46$1 digitaldaemon.com...
 Probably only Walter would know how hard something like this would be to 
 implement, but it would be wickedly powerful.
I know it'd be cool, and I want to do it. But it's a 2.0 thing.
 BTW, it's not a big deal, but why is "is" required to compare types.  Does 
 it make it easier for the compiler to parse or something?  Otherwise, I 
 don't see why it's necessary.
It makes the grammar straightforward.
Feb 09 2006