I suspect that this is similar to the issue I asked about here: https://forum.dlang.org/post/vukxaqprjbyrdpiou...@forum.dlang.org, but I can't figure it out.

This compiles:

---
private mixin template assign(string op_)
{
  ref auto opOpAssign(string op, this RHS)(RHS rhs) if (op == op_)
  {
    mixin("x " ~ op ~ "= rhs.x;");
    return this;
  }
}

struct V
{
  int x;

  mixin assign!"+";
  // mixin assign!"-";
}

unittest
{
  auto v = V(2);
  v += v;
  assert(v.x == 4);
}
---

However, if I uncomment the second mixin, there is an error "v is not a scalar, it is a V". I guess I somehow need to merge these overloads, but I don't know how.

Reply via email to