std.algorithm.cmp doesn't seem to support numeric types?
DNoob
operator97 at gmail.com
Wed Oct 16 19:25:18 UTC 2019
I'm just learning D, so it's very possible that I'm missing a
more appropriate function that exists elsewhere, but basically I
found today that while I could easily write a cmp function that
worked for everything, the one in std.algorithm doesn't seem to:
import std.stdio, std.algorithm;
pure nothrow @nogc @system byte my_cmp(T1, T2)(T1 a, T2 b)
{
if (a < b)
{
return -1;
}
else if (a == b)
{
return 0;
}
else
{
return 1;
}
}
void main()
{
//template error on the next line if uncommented
//writeln(cmp(1, 2));
writeln(my_cmp(1, 2));
}
Any advice would be much appreciated!
More information about the Digitalmars-d-learn
mailing list