cannot sort an array of char
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Nov 6 06:34:37 PST 2014
On 11/5/14 7:54 AM, Ivan Kazmenko wrote:
> Hi!
>
> This gives an error (cannot deduce template function from argument types):
>
> -----
> import std.algorithm;
> void main () {
> char [] c;
> sort (c);
> }
> -----
>
> Why is "char []" so special that it can't be sorted?
Because sort works on ranges, and std.range has the view that char[] is
a range of dchar without random access. Nevermind what the compiler
thinks :)
I believe you can get what you want with std.string.representation:
import std.string;
sort(c.representation);
-Steve
More information about the Digitalmars-d-learn
mailing list