another question on hidden mixin names

60rntogo 60rntogo at gmail.com
Thu Sep 17 21:05:59 UTC 2020


I suspect that this is similar to the issue I asked about here: 
https://forum.dlang.org/post/vukxaqprjbyrdpioukwa@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.


More information about the Digitalmars-d-learn mailing list