My D Reference Notes

~= support

1. If you want to add ~= support for a struct, you do it by defining opOpAssign like this:

void opOpAssign(string op)(Foo x)

That works for any of D’s operators that take the form [op]=. Whatever op happens to be is forwarded to your opOpAssign function. To support ~=, you add

static if(op == "~")

to the opOpAssign function. If you instead do (as I always seem to do)

static if(op == "~=")

that code path applies for the ~== operator, which doesn’t exist in D. It would be impossible to ever call this version of opOpAssign unless you did it manually: foo.opOpAssign!("~=")(x), which would not make any sense.


⤺ Back to the List of Posts