sorting a string
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jul 14 13:28:06 PDT 2017
On 7/14/17 3:50 PM, Anton Fediushin wrote:
> On Friday, 14 July 2017 at 17:23:41 UTC, Steven Schveighoffer wrote:
>> Don't do this, because it's not what you think. It's not actually
>> calling std.algorithm.sort, but the builtin array sort property. This
>> will be going away soon.
>
> This sucks. I know, that `.sort` will be removed, but I thought it won't
> break any code.
>
>> With 2.075, it won't compile even without the parentheses, because a
>> char[] is not an array according to std.algorithm...
>
> But why? This should be true for `char[]`, isn't it?
> -----
> if ((ss == SwapStrategy.unstable && (hasSwappableElements!Range ||
> hasAssignableElements!Range) || ss != SwapStrategy.unstable &&
> hasAssignableElements!Range) && isRandomAccessRange!Range &&
> hasSlicing!Range && hasLength!Range)
> -----
> (It's from https://dlang.org/phobos/std_algorithm_sorting.html#sort)
static assert(!isRandomAccessRange!(char[]));
static assert(!hasSlicing!(char[]));
static assert(!hasAssignableElements!(char[]));
static assert(!hasSwappableElements!(char[]));
static assert(!hasLength!(char[]));
It's because of autodecoding :) Phobos does not view char[] as an array,
but rather a range of decoded dchar elements. It causes no end of problems.
-Steve
More information about the Digitalmars-d-learn
mailing list