Should opIndex completely override alias this?

kenji hara k.hara.pg at gmail.com
Fri May 11 10:19:18 PDT 2012


2012/5/12 Trass3r <un at known.com>:
> As soon as you define an opIndex, alias this isn't considered anymore.
> Is this wanted behavior?
>
> I'd have expected this to work:
>
>        T[] data;
>        T opIndex(size_t i, size_t j)
>        {
>                return data[i*numCols+j];
>        }
>        alias data this;
>
> Then dynmap[3] would work by using data directly.
> But: opIndex (ulong i, ulong j) is not callable using argument types (int)

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


More information about the Digitalmars-d mailing list