std.algorithm.cmp is conflicting with itself.

Paul Backus snarwin at gmail.com
Thu Aug 11 18:10:31 UTC 2022


On Thursday, 11 August 2022 at 17:46:00 UTC, realhet wrote:
> Here's the utility module:
> ```d
> module testcmpmodule;
>
> //publicly output these modules, like I did in my always used 
> 'utils' module.
> public import std.algorithm, std.math, std.stdio;
>
> import std.range, std.traits;
>
> //create function overload group
> public import std.algorithm : cmp;
> public import std.math      : cmp;
>
> auto cmp(A, B)(in A a, in B b)
> if(!(isInputRange!A && isInputRange!B)          //exclude 
> std.algorithm.cmp
> && !(isFloatingPoint!A && isFloatingPoint!B))   //exclude 
> std.math.cmp
> {
>   return a==b ? 0 : a<b ? -1 : 1; //last resort
> }
>
> ```
>
> The other module that publishes the utility module:
> ```d
> module testcmpmodule2;
>
> public import std.algorithm, testcmpmodule, std.stdio;
>
> void w(A...)(in A a){ writeln(a); }
> ```

What's happening here is that the overload set created by the 
utility module is conflicting with the overload set created by 
the `public import` in `testcmpmodule2`. If you remove 
`std.algorithm` from `testcmpmodule2`'s `public import` line, the 
code compiles successfully.


More information about the Digitalmars-d-learn mailing list