Should opIndex completely override alias this?

David d at dav1d.de
Fri May 11 10:53:40 PDT 2012


> struct S(T)
> {
>      T data;
>      alias data this;
>
>      int opIndex()(size_t i, size_t j)
>      {
>          return 100; // specialized opIndex
>      }
>      auto opIndex(A...)(A args) if (A.length != 2)
>      {
>          return data[args];  // forwarding
>      }
> }
> void main()
> {
>      auto s = S!(int[])([1,2]);
>      assert(s[1,2] == 100);
>      assert(s[0] == 1);
>      assert(s[1] == 2);
> }

I want alias :/

struct S(T)
{
      T data;
      alias data this;

      int opIndex()(size_t i, size_t j)
      {
          return 100; // specialized opIndex
      }
      alias data.opIndex opIndex;
}


More information about the Digitalmars-d mailing list