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

Tejas notrealemail at gmail.com
Mon Aug 16 05:26:00 UTC 2021


On Sunday, 15 August 2021 at 20:41:51 UTC, james.p.leblanc wrote:
> 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

If you're finding the spec too hard, please try Ali's book. I'm 
sharing the part on operator overloading below:

http://ddili.org/ders/d.en/operator_overloading.html

Please ping if you still have problems; I'll then write a full 
program.



More information about the Digitalmars-d-learn mailing list