On Saturday, 8 June 2013 at 09:16:23 UTC, monarch_dodra wrote:
On Saturday, 8 June 2013 at 08:52:22 UTC, Jonathan M Davis wrote:
However, we really, really need to deprecate the built-in sort - especially when a pair of parens can make the difference between whether you call the built-in sort or std.algorithm's sort - and it's particularly broken with
regards to Unicode.

- Jonathan M Davis

Or anything that uses non-POD comparison (opCmp) for that matter:

//----
import std.stdio;
import std.algorithm;
struct S
{
    int i;
    int opCmp(S o)
    {
       return (i < o.i) - (i > o.i); //inverse order
    }
}

void main()
{
    auto a = [S(1), S(2), S(3)];
    writeln(a); //[S(1), S(2), S(3)]
    a.sort;
    writeln(a); //[S(1), S(2), S(3)]
    a.sort();
    writeln(a); //[S(3), S(2), S(1)]
}
//----

I had pretty much forgotten ".sort" even existed (it really never even crossed my mind that it could be built-in), and given the push for optional parenthesis in general (especially in UFCS call chains), I can say I am surprised by this behavior.

Wow, that's much worse than in my example... indeed very unexpected behaviour.

Reply via email to