Multiple alias this, what's the hold up?

user1234 user1234 at 12.de
Mon Jun 17 19:38:14 UTC 2019


On Monday, 17 June 2019 at 18:56:13 UTC, 12345swordy wrote:
> On Monday, 17 June 2019 at 18:31:18 UTC, Timon Gehr wrote:
>> On 17.06.19 15:48, Mike Franklin wrote:
>>> [...]
>>
>> This is not an assignment. It is an initialization. 
>> opAssignRight would do nothing for this case.
>>
>>> [...]
>>
>> 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.

Yes, the T opImplicitConv(T)(){} mentioned previously could be 
used for that too.

"writeln(foo(S(3)));"  rewritten  
"writeln(foo(S(3).opImplicitConv!int()));"


More information about the Digitalmars-d mailing list