Getting a working example of opIndexAssign using opSlice ... have troubles ...

james.p.leblanc james.p.leblanc at gmail.com
Sun Aug 15 20:41:51 UTC 2021


Greetings,

I have been trying to get a working example of slice assignment 
operator
overloading ... and am befuddled.  From the spec (section 
20.6.2), the
code below appears:

     struct A
     {
         int opIndexAssign(int v);  // overloads a[] = v
         int opIndexAssign(int v, size_t[2] x);  // overloads a[i 
.. j] = v
         int[2] opSlice(size_t x, size_t y);     // overloads i .. 
j
     }

     void test()
     {
         A a;
         int v;

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

I have hacked at this trying to get a simple working example.  
Could
anyone guide me here please?

Best Regards,
James



More information about the Digitalmars-d-learn mailing list