Skip to content

Commit

Permalink
Fix opBinary[Right]CustomFloat op CustomFloat ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilsonator committed Nov 6, 2018
1 parent a7485d9 commit 247cf0a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions std/numeric.d
Original file line number Diff line number Diff line change
Expand Up @@ -568,16 +568,28 @@ public:
}

/// ditto
// Define an opBinary `CustomFloat op CustomFloat` so that those below
// do not match equally, which is disallowed by the spec:
// https://dlang.org/spec/operatoroverloading.html#binary
real opBinary(string op,T)(T b)
if (__traits(compiles, mixin(`get!real`~op~`b`)))
if (__traits(compiles, mixin(`get!real`~op~`b.get!real`)))
{
return mixin(`get!real`~op~`b.get!real`);
}

/// ditto
real opBinary(string op,T)(T b)
if ( __traits(compiles, mixin(`get!real`~op~`b`)) &&
!__traits(compiles, mixin(`get!real`~op~`b.get!real`)))
{
return mixin(`get!real`~op~`b`);
}

/// ditto
real opBinaryRight(string op,T)(T a)
if ( __traits(compiles, mixin(`a`~op~`get!real`)) &&
!__traits(compiles, mixin(`get!real`~op~`b`)))
!__traits(compiles, mixin(`get!real`~op~`b`)) &&
!__traits(compiles, mixin(`get!real`~op~`b.get!real`)))
{
return mixin(`a`~op~`get!real`);
}
Expand Down

0 comments on commit 247cf0a

Please sign in to comment.