alias this
Rob T
rob at ucora.com
Sat Dec 1 12:25:54 PST 2012
On Friday, 30 November 2012 at 23:11:28 UTC, js.mdnq wrote:
>
> I've seen that, how does it work?
>
> struct A{
> Sometype val1;
> int val2;
> alias val1 this;
> alias val2 this; //???
> }
>
>
> How can A act both as Sometype and int? (at least without major
> issues) Does the compiler try to choose the appropriate alias
> depending on the lvalue or rvalue?
If the D devs really do implement alias this fully, then the
compiler will have to figure out which call to make based on both
the return type and also the argument list. If a decision is
ambiguous then a compiler error results. However to do alias this
correctly and fully you'll have to effectively implement full
signature overloading.
A few days back I started a thread asking why full function
signature overloading was not being considered, which I think
would be very useful to have, but it looked like the devs did not
want to implement due to the complications involved (no other
reason was given than that). IMHO they can do it and should do
it, and will eventually have to do it, but we'll see. Also for
some reason no one thought that implementing alias this fully
would mean implementing full signature overloading, or at least
implementing all of the things required to implement it.
--rt
More information about the Digitalmars-d-learn
mailing list