alias this
js.mdnq
js_adddot+mdng at gmail.com
Sat Dec 1 13:33:14 PST 2012
On Saturday, 1 December 2012 at 20:25:55 UTC, Rob T wrote:
> 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
By full signature overloading I assuming you also the return type?
I don't see why it is so complicated in any case since a return
type can just be seen as a ref argument:
int myfunc()
is basically the same as
void myfunc(ref int returnvalue)
More information about the Digitalmars-d-learn
mailing list