On Wednesday, 5 November 2014 at 13:34:05 UTC, Marc Schütz wrote:
On Wednesday, 5 November 2014 at 12:54:03 UTC, 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?

For example, if I know the array contains only ASCII characters, sorting it sounds no different to sorting an "int []".

Hmm... this doesn't work either:

    import std.algorithm;
    import std.utf;
    void main () {
        char [] c;
        sort (c.byCodeUnit);
    }

But IMO it should.

So, you imply that to use a char array as a RandomAccessRange, I have to use byCodeUnit? (and it should work, but doesn't?)

Fine, but how does one learn that except by asking here? Googling did not produce meaningful results for me.

For example, isRandomAccessRange[0] states the problem:
-----
Although char[] and wchar[] (as well as their qualified versions including string and wstring) are arrays, isRandomAccessRange yields false for them because they use variable-length encodings (UTF-8 and UTF-16 respectively). These types are bidirectional ranges only.
-----
but does not offer a solution. If (when) byCodeUnit does really provide a random-access range, it would be desirable to have it linked where the problem is stated.

[0] http://dlang.org/phobos/std_range.html#.isRandomAccessRange

Reply via email to