Should opIndex completely override alias this?

Artur Skawina art.08.09 at gmail.com
Fri May 11 10:32:52 PDT 2012


On 05/11/12 19:03, Trass3r wrote:
> 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)

That would mean a hidden opIndex overload (or more); not only can that make
debugging harder, you then also would have to always make sure to override
every opIndex present in 'data' if the indexing were to work differently in
dynmap and T[]. Explicit forwarding is slightly more verbose, but much safer.

artur


More information about the Digitalmars-d mailing list