another question on hidden mixin names

Simen Kjærås simen.kjaras at
Thu Sep 17 22:07:54 UTC 2020

On Thursday, 17 September 2020 at 21:05:59 UTC, 60rntogo wrote:
> struct V
> {
>   int x;
>   mixin assign!"+";
>   // mixin assign!"-";
> }
> 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.

Usually, that would be:

struct V {
     int x;

     mixin assign!"+" a;
     mixin assign!"-" b;
     alias opOpAssign = a.opOpAssign;
     alias opOpAssign = b.opOpAssign;

However, I can't seem to get that working. It seems to be an 
instance of this issue:

Note that explicitly calling the methods does work:


I don't know any good workarounds for this, you'll probably have 
to write a separate opOpAssign method for V that performs the 
forwarding to the mixed-in methods. This is, to put it very 
nicely, not an optimal solution.

btw, I'm somewhat surprised by your use of a template this 
Generally this will work, but you're probably better off with

     ref auto opOpAssign(string op)(typeof(this) rhs) if (op == 


More information about the Digitalmars-d-learn mailing list