AliasSeq different from just using the symbol name(s)?

Paul Backus snarwin at gmail.com
Thu Apr 15 19:53:57 UTC 2021


On Thursday, 15 April 2021 at 19:38:04 UTC, z wrote:
> I understand that it won't be possible to pinpoint the cause 
> without a reduced test case, but :
>
> ```D
> int[] a,b,c,d,e;
> void templatef(args...){/*...*/}
> //...
> auto seq = AliasSeq!(b,c,d);
> templatef!(a,seq,e);
> templatef!(a,b,c,d,e); //am i being mistaken for thinking these 
> two template calls should be equivalent in behavior?
> ```
> And if not, does it mean that the problem i encountered is a 
> possible bug?

They're not *exactly* the same. When you write

     auto seq = AliasSeq!(a, b, c);

...you are declaring a sequence of three *new* array variables 
[1] and initializing them with copies of the original arrays. 
It's as though you'd written:

     auto seq_a = a;
     auto seq_b = b;
     auto seq_c = c;
     alias seq = AliasSeq!(a, b, c);

If you want to refer directly to the original variables, you need 
to create your sequence with `alias` instead of `auto`:

     alias seq = AliasSeq!(a, b, c);

[1] 
https://dlang.org/articles/ctarguments.html#type-seq-instantiation


More information about the Digitalmars-d-learn mailing list