Hello,

I try to make an overload group of cmp() functions in my utility module but everything works well except when I import some 3rd party module that imports std.algorithm. Then I get an error:
C:\D\testCmpOverload.d(11,8): Error:
function `std.algorithm.comparison.cmp!(string, string).cmp` at
c:\D\ldc2\bin\..\import\std\algorithm\comparison.d(625,6)
conflicts with
function `std.algorithm.comparison.cmp!(string, string).cmp` at c:\D\ldc2\bin\..\import\std\algorithm\comparison.d(625,6)

It is conflicting with itself.
My question is that how to solve this without choosing a different identifier, other than 'cmp'?

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); }
```

The main module:
```d
import testcmpmodule2;

void main(){
  w(cmp(.1, .2));   //std.math.cmp
  w(cmp("a", "b")); //std.algorithm.cmp   <- here's the error
  w(cmp(1, 2));     //my cmp
}
```

I have a project with 40K lines. And I don't even have to use public import in the 'second' module, like in this example, the error is happenning because something pulls it in.

My not so good solution was this:
```d
alias cmp_ = cmp; //so wherever there is a conflict, I only have to put a _ symbol after the cmp, but that's still ugly.


To be more precise:
I have a het.math module where I implement math routines that are close to opengl. That module does a log of patching of various std functions, mainly enable them to work on vector/matrix. I also have a het.utils module which publicly imports het.math, and also many std modules. And finally when I make an application using the complete framework, I lost the game finding what imports std.algorithm and thus ruining my fragile function overload groups.

Also I wonder why there is no cmp() function for integers in the std library? It's easy to code (a-b or a==b?0:a<b?-1:1) but still, I can do mistakes. (And I did: many of my comparisons had bugs :D So I wan't to centralize cmp())


Thank You in advance!

Reply via email to