Should opIndex completely override alias this?

Artur Skawina art.08.09 at gmail.com
Fri May 11 10:36:57 PDT 2012


On 05/11/12 19:22, Mehrdad wrote:
> On Friday, 11 May 2012 at 17:19:28 UTC, kenji hara wrote:
>> This is expected behavior.
>>
>> 'alias this' works as proper super type.
>>
>> struct S { T[] data; alias data this; }
>>
>> In this code, S behaves as it is derived from T[] .
>>
>> Following to this view, the definition of opIndex in S overrides (and
>> hides) T[]'s opIndex completely.
>>
>> Kenji Hara
> 
> How do you overcome this, in the case where you don't know the data type of 'data' (so you don't know what the overloads might look like, maybe because it's a template)?

Not quite sure what you mean, but

    auto opIndex(A...)(A a) { return data[a]; }

artur


More information about the Digitalmars-d mailing list