Thread overview
[Issue 19365] operator overloading set of mixin template is not considered
[Issue 19365] Allow aliasing templated functions from mixin template to add them to overload set
Dec 07
Dennis
Dec 07
Dennis
December 06
https://issues.dlang.org/show_bug.cgi?id=19365

Adam D. Ruppe <destructionator@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator@gmail.com

--- Comment #1 from Adam D. Ruppe <destructionator@gmail.com> ---
That's not a bug, that's by design. It allows you to override an overload set from a mixin template while keeping the other things.

To merge the sets, you use alias:

struct S {
    mixin Operators ops;
    int opBinary(string op: "*")(S rhs) {return 2;}
    alias opBinary = ops.opBinary;
}


However, while that works with every other case, with this one.... it is giving me

Error: alias `ooooo.S.opBinary` conflicts with template ooooo.S.opBinary(string
op : "*")(S rhs) at ooooo.d(7)


So that *might* be a bug, it isn't merging specialized templates... I was going to close this immediately, but maybe this specific thing is legit.

To work around that, offer a dispatcher function instead of an alias:


struct S {
    mixin Operators ops;
    int opBinary(string op: "*")(S rhs) {return 2;}
    int opBinary(string op)(S rhs) {
        // forward all others to the mixin
        return ops.opBinary!op(rhs);
    }
}


see for design: https://dlang.org/spec/template-mixin.html#mixin_scope

--
December 07
https://issues.dlang.org/show_bug.cgi?id=19365

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86                         |All
            Summary|operator overloading set of |Allow aliasing templated
                   |mixin template is not       |functions from mixin
                   |considered                  |template to add them to
                   |                            |overload set
                 OS|Windows                     |All
           Severity|normal                      |enhancement

--- Comment #2 from Dennis <dkorpel@live.nl> ---
(In reply to Adam D. Ruppe from comment #1)
> So that *might* be a bug, it isn't merging specialized templates... I was going to close this immediately, but maybe this specific thing is legit.

Thanks for the workaround.

--
December 07
https://issues.dlang.org/show_bug.cgi?id=19365

--- Comment #3 from Dennis <dkorpel@live.nl> ---
(In reply to Adam D. Ruppe from comment #1)
> So that *might* be a bug, it isn't merging specialized templates... I was going to close this immediately, but maybe this specific thing is legit.

I also noticed that it matters whether you put the alias before or after the new opBinary method.

Anyway, I'll change this to an enhancement, thanks for the workaround. (I happily replace the ugly string mixin with a dispatcher function.)

--