"+=" (overloads) with custom array slices on both lhs, and rhs ??

james.p.leblanc james.p.leblanc at gmail.com
Mon Sep 6 04:08:44 UTC 2021


On Sunday, 5 September 2021 at 21:25:06 UTC, jfondren wrote:
> On Sunday, 5 September 2021 at 20:49:08 UTC, james.p.leblanc 
> wrote:

> Here's a reduction of your myArray.d that works with your 
> unchanged usage code:
>
> ```d
> module myArray;
> import std.stdio;
>
>     void opOpAssign(string op)(myArray rhs) if (op == "+") {
>         foreach (i; 0 .. length) {
>             mixin("ptr[i] " ~ op ~ "= rhs.ptr[i];");
>         }
>     }
>
> ```

Wow, these quick and helpful replies are gratefully received!

They have helped me learn many new aspects of D (especially the 
overloading!)

Serious thanks to **all**.

Best Regards,
James



More information about the Digitalmars-d-learn mailing list