[Issue 5924] New: schwartzSort of Tuple!(char)[]

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 3 04:44:54 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5924

           Summary: schwartzSort of Tuple!(char)[]
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2011-05-03 04:41:04 PDT ---
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);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list