Multiple alias this, what's the hold up?

12345swordy alexanderheistermann at gmail.com
Mon Jun 17 18:56:13 UTC 2019


On Monday, 17 June 2019 at 18:31:18 UTC, Timon Gehr wrote:
> On 17.06.19 15:48, Mike Franklin wrote:
>> void main()
>> {
>>      S s;
>>      s = 1;
>>      int i = s;  // No way to make this work in the library.  
>> We need `opAssignRight`.
>> }
>> ```
>> ...
>
> This is not an assignment. It is an initialization. 
> opAssignRight would do nothing for this case.
>
>> I think if we had an `opAssignRight` feature (with friends) we 
>> could move the entire implementation of `alias this` to the 
>> library.
>
> I don't think that works. (And I don't necessarily agree that 
> it is desirable. See Ethan's excellent post noting issues with 
> compile times.)
>
> This is another case you can't do in the library right now:
>
> struct S{
>     int x;
>     alias x this;
> }
>
> int foo(int x){
>     return x;
> }
>
> void main(){
>     import std.stdio;
>     writeln(foo(S(3)));
> }

AKA implicit conversion. Which D needs if it were to deprecate 
alias this.


More information about the Digitalmars-d mailing list