Passing several tuples (T...) to templates without expanding them

monarch_dodra monarchdodra at gmail.com
Wed Mar 13 05:34:10 PDT 2013


On Wednesday, 13 March 2013 at 11:26:24 UTC, simendsjo wrote:
>
> Ahem.. Seems TypeTuple is exactly like my Tuple, so I'll change 
> my code to use TypeTuple. The question still stands though..
> If it's not possible, as you say, I'll try to figure out a 
> workaround..

Yeah, Tuple is a Tuple in the C++ definition: An aggregate.

I'm don't have a solution for you. TypeTuple really isn't a 
"type", so you can't really *not* expand them, nor pass them "as 
is" to a template, or anything else like that.

It sounds like you are trying to work around the problem of 
"template function with two var-arg arguments"?

If you know each var-args relative size, then you can alias a 
slice:

template foo(Args...)
{
     alias A = Args[0 .. $/2];
     alias B = Args[$/2 .. $];

     void foo()
     {
         foreach(i, T; A) {
             pragma(msg, i, " ", T);
             pragma(msg, isEqual!(T, B[i]));
         }
     }
}

void main()
{
     alias TypeTuple!(int, 1, short) A;
     alias TypeTuple!(int, 1, short) B;

     foo!(A, B)();
}

Not perfect, but works all right.


More information about the Digitalmars-d-learn mailing list