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!

Reply via email to