[Issue 10318] Built-in array sort usage warning, then deprecation, and finally removal

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 27 18:04:19 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=10318



--- Comment #8 from bearophile_hugs at eml.cc 2013-12-27 18:04:17 PST ---
(In reply to comment #7)

> I don't think it's possible to simply infer purity.

The D language is able to infer purity for templates. So if sort() is not
(wealkly) pure, then there is something that forces it to be not pure. Such
parts should be found and fixed.


> (2) This may be a non-issue but Phobos cannot sort char[] arrays

This is by design. On the other hand sorting char[] is a common need for me (I
have not yet had to sort a wchar[]).

This works already:

void main() {
    import std.algorithm, std.string;
    char[] txt = "acb".dup;
    txt.representation.sort();
    assert(txt == "abc");
}


But that's not enough, as I'd like to use sort() in UFCS chains too.

A simple solution is to add to std.ascii a charsSort() function for this
purpose. But then you want charsPartialSort, charsSchwartzSort, etc. And this
is a bit too much. So this doesn't seem a very good idea.

Another solution is to introduce a unrepresentation() function, opposite of
std.string.representation. With it you can write this long code:

string txt = "acb;
char[] txt2 = txt.dup.representation.sort().release.unrepresentation;

Similar code could be written with partialSort, schwartzSort, multiSort, topN,
etc.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list