Bug 5924 – schwartzSort of Tuple!(char)[]

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-05-03T04:41:00Z
Last change time
2013-02-25T20:34:24Z
Keywords
rejects-valid
Assigned to
andrei
Creator
bearophile_hugs

Comments

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
Comment #2 by bearophile_hugs — 2013-02-25T04:51:08Z
Comment #3 by github-bugzilla — 2013-02-25T20:28:37Z