Multiple alias this, what's the hold up?

Mike Franklin slavo5150 at yahoo.com
Mon Jun 17 13:48:45 UTC 2019


On Monday, 17 June 2019 at 13:13:07 UTC, Adam D. Ruppe wrote:
> On Sunday, 16 June 2019 at 09:26:21 UTC, Mike Franklin wrote:
>> Contrived, naive, very incomplete illustration:
>>
>>     static foreach(m; __traits(allMembers, typeof(f)))
>>     {
>>         mixin(
>>             ReturnType!(__traits(getMember, typeof(f), 
>> m)).stringof
>>             ~ " " ~ m ~ "()"
>>             ~ "{" ~ __traits(identifier, f) ~ "." ~ m ~ "(); }"
>>         );
>>     }
>
>
> It has kinda become my thing to comment on this whenever I can, 
> but that code is needlessly hideous.

I know and thank you for posting improvements, but it was just an 
illustration to convey that there may be a preferred path forward 
for multiple alias this: implement it in the library.

So far I've only been able to find one `alias this` 
characteristic that can't be implemented in the library:

```
struct S
{
     int i;

     void opAssign(int v)
     {
         i = v;
     }
}

void main()
{
     S s;
     s = 1;
     int i = s;  // No way to make this work in the library.  We 
need `opAssignRight`.
}
```

I think if we had an `opAssignRight` feature (with friends) we 
could move the entire implementation of `alias this` to the 
library.  It would probably be a few hundred lines, but probably 
less than what it takes to implement in the compiler.  We could 
even lower the `alias field this;` expression to `mixin 
AliasThis!(field);` so the user wouldn't know anything happened, 
assuming of course that the implementation of `AliasThis` was 
correct.

I believe there have been 3 different PRs from the DIP66 author 
in the past few years attempting to implement multiple alias 
this, and none of them have been merged.  Now there's talk that 
multiple alias this shouldn't ever be implemented.  It seems to 
me the path forward is a pure library implementation.  And, it 
would be nice to delete the hundreds, if not thousands, of lines 
of code needed to implement `alias this` in the compiler, along 
with all of the bugs that accompany it.

Mike



More information about the Digitalmars-d mailing list