Using multiple mixin templates to implement operator overloading

Adam D. Ruppe destructionator at gmail.com
Sat Dec 12 20:25:48 UTC 2020


On Saturday, 12 December 2020 at 18:14:31 UTC, Paul Backus wrote:
> IMO this is one of the stupider design decisions in D, but it's 
> unlikely it will ever be fixed.

It is useful in several other contexts though, including user 
overriding and private data stores for the mixin.

> The easiest workaround is to use string mixins instead, which 
> work the way you'd expect them to.

But yeah. The other alternative is to alias them together:

class A {
    mixin Whatever a; // need to give it a name here to reference 
later
    mixin Whatever b;

    // explicitly merge overloads here
    alias opBinary = a.opBinary;
    alias opBinary = b.opBinary;
}


Or you can do a forwarder function yourself but that's getting 
even more a hassle. Sometimes appropriate though.


More information about the Digitalmars-d-learn mailing list