alias this

js.mdnq js_adddot+mdng at gmail.com
Fri Nov 30 15:11:27 PST 2012


On Friday, 30 November 2012 at 21:46:47 UTC, Rob T wrote:
> On Friday, 30 November 2012 at 14:14:36 UTC, js.mdnq wrote:
>> On Friday, 30 November 2012 at 14:02:42 UTC, Andrej Mitrovic 
>> wrote:
>>> On 11/30/12, js.mdnq <js_adddot+mdng at gmail.com> wrote:
>>>> alias t this;
>>>
>>> This should explain: http://dlang.org/class.html#AliasThis
>>
>> Thanks, I'm sure I saw that at some point but I guess it just 
>> didn't sink in. This seems really cool and might solve a 
>> problem I had much more elegantly...
>
> Note that multiple alias this declarations are slated to be 
> allowed, but have not yet been implemented:
>
> -----------
> Multiple AliasThis are allowed. For implicit conversions and 
> forwarded lookups, all AliasThis declarations are attempted; if 
> more than one AliasThis is eligible, the ambiguity is 
> disallowed by raising an error. Note: Multiple AliasThis is 
> currently unimplemented.
> -----------

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?






More information about the Digitalmars-d-learn mailing list