AliasSeq!() deletes item in type list

Paul Backus snarwin at gmail.com
Sat Aug 22 21:52:53 UTC 2020


On Saturday, 22 August 2020 at 21:45:35 UTC, data pulverizer 
wrote:
> Hi all,
>
> just wandering if this is a bug, I certainly didn't expect the 
> output:
>
> ```d
> alias AliasSeq(T...) = T;
> alias Nothing = AliasSeq!();
>
> template MyTemplate(S, Args...)
> {
>   pragma(msg, "Args: ", Args);
> }
>
> void main()
> {
>   alias types = AliasSeq!(bool, string, ubyte, short, ushort);
>   alias x = MyTemplate!(Nothing, types);
> }
> ```
>
> Output (first item is gone):
>
> ```terminal
> Args: (string, ubyte, short, ushort)
> ```

AliasSeq's don't nest and automatically expand when you use them, 
so when you write

     MyTemplate!(Nothing, types)

it gets expanded to

    MyTemplate!(bool, string, ubyte, short, ushort)

So `bool` gets bound to the first parameter, `S`, and the rest of 
the arguments get bound to `Args`.

If you want a non-expanding version of AliasSeq, you can write 
one like this:

     template AliasTuple(Args...) {
         alias expand = Args;
     }


More information about the Digitalmars-d-learn mailing list