On Sunday, 15 August 2021 at 21:15:02 UTC, Bastiaan Veelo wrote:
On Sunday, 15 August 2021 at 20:41:51 UTC, james.p.leblanc

— Bastiaan.

Bastiaan,

Thanks kindly for your response!

Unfortunately, I do not see what the program does. I mean A is a structure that has only functions. So, how are any elements of this being set to
the value of v?

I tried extending the code mentioned by adding a member array, but no
luck.

I often have difficulties to understand the notations used in the spec,
and only sometimes can I extend them to working examples.

Would it be possible to add the last couple of details regarding
an array member?  I attempted but the values always remain zero
even when I set v=4.


import std;

    struct A
    {
       int[5] a;
       int opIndexAssign(int v) // overloads a[] = v
       {
          writeln(__FUNCTION__);
          return 42;
       }
int opIndexAssign(int vh, size_t[2] x) // overloads a[i .. j] = v
       {
          writeln(__FUNCTION__);
          return 43;
       }
       int[2] opSlice(size_t x, size_t y)     // overloads i .. j
       {
          writeln(__FUNCTION__);
          return [44, 45];
       }
    }

    void main()
    {
       A a;
       int v=4;
       writeln(a);

       a[] = v;  // same as a.opIndexAssign(v);
       writeln(a);
a[3..4] = v; // same as a.opIndexAssign(v, a.opSlice(3,4));
       writeln(a);
    }


Thanks once again,
James












Reply via email to