cannot infer argument types

bearophile bearophileHUGS at lycos.com
Wed Nov 13 02:02:15 PST 2013


Jonathan M Davis:

> In addition, I would point out that sequence.dup.sort is using 
> the built-in
> sort for arrays rather than std.algorithm.sort (you have to 
> have the parens
> when calling sort on array, or it'll use the built-in one), and 
> the built-in
> sort for arrays is not only buggy, but it's going to be 
> deprecated, so I
> wouldn't advise using it. And yes, the means that you'll have 
> to have a
> random-access range, meaning that you'll need to convert your 
> string to
> dchar[], but at least then you'll get a sort that works and 
> isn't going to be
> removed from the language (IIRC, the built-in sort doesn't sort 
> Unicode
> properly anyway). If you know that you only have ASCII 
> characters, then you
> can use ubyte[] instead, but char[] isn't going to work, since 
> it's not a random-access range.

I'd like dmd to give a deprecation warning when you use a 
built-in sort.

And regarding sorting ASCII chars, it's a common need. I usually 
do it this way (if the input array of chars is mutable the code 
could spare the dup):

string s = "test";
string t = cast(string)(s.dup.representation.sort().release);

See also:
https://d.puremagic.com/issues/show_bug.cgi?id=10162

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list