digitalmars.D.learn - AliasSeq!() deletes item in type list
- data pulverizer (32/32) Aug 22 2020 Hi all,
- Paul Backus (14/34) Aug 22 2020 AliasSeq's don't nest and automatically expand when you use them,
- data pulverizer (6/15) Aug 22 2020 That totally makes sense, it was in code where S could be
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) ``` If I do: ```d alias y = AliasSeq!(Nothing, types); pragma(msg, "y: ", y); ``` I'd get expected behaviour: ```terminal y: (bool, string, ubyte, short, ushort) ``` Any added insights as to why this happens would be be much appreciated. Thanks in advance.
Aug 22 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; }
Aug 22 2020
On Saturday, 22 August 2020 at 21:52:53 UTC, Paul Backus wrote:On Saturday, 22 August 2020 at 21:45:35 UTC, data pulverizer wrote: 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`.That totally makes sense, it was in code where S could be something some times but Nothing at other times, and I was getting issues with the Nothing situation, but when I look at your explanation I should have totally expected it. Thanks again!
Aug 22 2020