Thread overview | |||||
---|---|---|---|---|---|
|
August 22, 2020 AliasSeq!() deletes item in type list | ||||
---|---|---|---|---|
| ||||
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. |
August 22, 2020 Re: AliasSeq!() deletes item in type list | ||||
---|---|---|---|---|
| ||||
Posted in reply to data pulverizer | 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;
}
|
August 22, 2020 Re: AliasSeq!() deletes item in type list | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | 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!
|
Copyright © 1999-2021 by the D Language Foundation