Comment #0 by bearophile_hugs — 2011-05-03T04:41:04Z
D2 code:
import std.algorithm, std.typecons;
void main() {
//Tuple!(int)[] chars; // OK
Tuple!(char)[] chars; // Error
schwartzSort!((c){ return c[0]; })(chars);
}
It doesn't compile with DMD 2.052:
...\dmd\src\phobos\std\algorithm.d(5911): Error: template instance SortedRange!(Zip!(char[],Tuple!(char)[]),myLess) does not match template declaration SortedRange(Range,alias pred = "a < b") if (isRandomAccessRange!(Range))
...\dmd\src\phobos\std\algorithm.d(5912): Error: SortedRange!(Zip!(char[],Tuple!(char)[]),myLess) is used as a type
You can't sort efficiently the items of an Unicode string because in general they don't have the same length. But a dynamic array of Tuple!(char) is composed by items 1 byte long, and generally it's not meant to be a string. So in this case I expect schwartzSort to be able to sort it.
Current workaround:
import std.algorithm, std.typecons;
void main() {
Tuple!(char)[] chars;
schwartzSort!((c){ return cast(int)c[0]; })(chars);
}
Comment #1 by github-bugzilla — 2013-02-24T16:52:47Z