AliasAssign - is this a bug?
Mathias LANG
geod24 at gmail.com
Wed Apr 28 09:07:15 UTC 2021
On Wednesday, 28 April 2021 at 00:29:46 UTC, Andrei Alexandrescu
wrote:
> Is this a bug? If not, where is the mistake in the code?
Not a bug, since `static foreach` does not introduce a scope,
you're trying to declare twice the same alias at the same scope,
the compiler rightfully flags it.
> If so, what would be a workaround? Thanks!
Depends on what you want to do. Either use a different name, but
it will fail as soon as you have more than one instantiation, or
re-assign the alias:
```D
template AliasThisType(T) {
alias A = AliasSeq!();
static foreach (U; AliasSeq!(__traits(getMember, T, "xyz"))) {
A = AliasSeq!(A, typeof(U)); // No more `alias` here
}
alias AliasThisType = A;
}
```
More information about the Digitalmars-d
mailing list