Problem with using std.math: abs and std.complex: abs at the same time

berni someone at something.org
Wed Sep 18 12:03:28 UTC 2019


The following code doesn't compile:

>import std.stdio;
>
>void main()
>{
>    import std.complex: abs, complex;
>    import std.math: abs;
>
>    auto a = complex(1.0,1.0);
>    auto b = 1.0;
>
>    writeln(abs(a));
>    writeln(abs(b));
>}

The error message depends on the order of the two import 
statements. Seems like the second import is actually ignored.

I hoped for a mechanism similar to overloading, which makes the 
compiler decide, which "abs" to use, depending on the type of the 
operand. Is there a way to do this? (As the code appears inside a 
template, something like std.math.abs() with static import 
doesn't work out well.)


More information about the Digitalmars-d-learn mailing list