cannot sort an array of char

Ivan Kazmenko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 11 03:07:35 PST 2014


IK>> Why is "char []" so special that it can't be sorted?

SS> Because sort works on ranges, and std.range has the view that
SS> char[] is a range of dchar without random access. Nevermind
SS> what the compiler thinks :)
SS>
SS> I believe you can get what you want with
SS> std.string.representation:
SS>
SS> import std.string;
SS>
SS> sort(c.representation);

Thank you for showing a library way to do that.
I ended up with using a cast, like "sort (cast (ubyte []) c)".
And this looks like a safe way to do the same.

Now, std.utf's byCodeUnit and std.string's representation seem 
like duplicate functionality, albeit with different input and 
output types (and bugs :) ).


More information about the Digitalmars-d-learn mailing list