Stop TypeTuple as template parameter from expanding
Tobias Brandt
tob.brandt at googlemail.com
Fri Nov 4 06:13:20 PDT 2011
I know of two options, both not ideal:
1)
First of all, you need to declare S as an alias.
A TypeTuple is a template, not a type.
template Test(alias S, T...)
{
pragma(msg, "S: " ~ S.stringof);
pragma(msg, "T: " ~ T.stringof);
}
Then you can pack the type list manually into a
template, like so:
template Pack(T...)
{
alias T unpack;
}
void main()
{
Test!(Pack!(A,B,C), A, B, C);
}
This prints:
S: Pack!(A, B, C)
T: (A, B, C)
2)
The other alternative would be a nested template:
template Test(S...)
{
template and(T...)
{
pragma(msg, "S: " ~ S.stringof);
pragma(msg, "T: " ~ T.stringof);
}
}
void main()
{
Test!MyList.and!(A, B, C);
}
This prints:
S: (A, B, C)
T: (A, B, C)
On 4 November 2011 11:02, Tobias Pankrath <tobias at pankrath.net> wrote:
> Hi,
>
> this is an example
> -----------------------------------------
> template Test(S, T...)
> {
> pragma(msg, "S: " ~ S.stringof);
> pragma(msg, "T: " ~ T.stringof);
> }
> alias TypeTuple!(A, B, C) MyList;
> struct A {};
> struct B {};
> struct C {};
>
>
> void main()
> {
> Test!(MyList, A, B, C);
> }
> --------------------------------------------
>
> If I compile this with dmd, it will print:
> --------------------------------------------
> S: A
> T: (B, C, A, B, C)
> test.d(153): Error: Test!(A,B,C,A,B,C) has no effect
> --------------------------------------------
>
> I don't want MyList to expand to the variadic template arguments. Instead
> I want to provide Test with to different typelists. So it should print
>
> --------------------------------------------
> S: (A, B, C)
> T: (A, B, C)
> --------------------------------------------
>
> How would you do this? Do I need an extra template TypeList?
>
> Thank you
>
> --
> Tobias
>
More information about the Digitalmars-d-learn
mailing list