Why are template alias parameters broken?
Menshikov
mensikovk817 at gmail.com
Fri Aug 27 19:02:49 UTC 2021
On Friday, 27 August 2021 at 19:00:27 UTC, Menshikov wrote:
> On Friday, 27 August 2021 at 18:47:56 UTC, Menshikov wrote:
>> It's work:
>>
>> ```d
>> template Foo(alias var)
>> {
>> void inc() { var++; }
>> }
>>
>> void main()
>> {
>> int v = 4;
>> alias foo = Foo!(v);
>> foo.inc();
>> assert(v == 5);
>> }
>> ```
>> But it doesn't work:
>> ```d
>> template Foo(alias var)
>> {
>> void inc() { var++; }
>> }
>>
>> void main()
>> {
>> struct V{
>> int a;
>> }
>> auto v = V(4);
>> alias foo = Foo!(v.a);
>> foo.inc();//err
>> assert(v.a == 5);
>> }
>> ```
>> Hence this applies to Alias!() and AliasSeq!()
>
> And it doesn't work
> ```d
> template Foo(alias var)
> {
> void inc() { var++; }//err
> }
>
> void main()
> {
> static struct V{
> int a;
> }
> auto v = V(4);
> mixin Foo!(v.a)foo;//err
> foo.inc();
> assert(v.a == 5);
> }
> ```
We open it ourselves, and it works:
```d
void main()
{
static struct V{
int a;
}
auto v = V(4);
void inc() { v.a++; }
inc();
assert(v.a == 5);
}
```
More information about the Digitalmars-d
mailing list