Multiple alias this, what's the hold up?
Timon Gehr
timon.gehr at gmx.ch
Mon Jun 17 18:31:18 UTC 2019
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)));
}
More information about the Digitalmars-d
mailing list