Should opIndex completely override alias this?

Mehrdad wfunction at hotmail.com
Fri May 11 11:12:18 PDT 2012


On Friday, 11 May 2012 at 18:09:13 UTC, Steven Schveighoffer 
wrote:
> On Fri, 11 May 2012 13:47:13 -0400, Mehrdad 
> <wfunction at hotmail.com> wrote:
>
>> On Friday, 11 May 2012 at 17:37:11 UTC, Artur Skawina wrote:
>>> 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
>>
>> What if it's const/pure/@safe/whatever though? Or the 
>> parameters have some attributes?
>>
>> (I guess this is a more general problem than opIndex 
>> specifically, though.)
>
> D solves this by automatically adding pure @safe nothrow to a 
> template function, wherever it is possible.
>
> However, it doesn't do this for const or immutable.
>
> -Steve

Yeah I remember that was a relatively recent fix, but there's 
still the issue of perfect forwarding that isn't possible in D:
http://stackoverflow.com/questions/7948865


More information about the Digitalmars-d mailing list