[Issue 5442] New: std.algorithm.sort problem with struct with char[10]

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 10 10:44:58 PST 2011


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

           Summary: std.algorithm.sort problem with struct with char[10]
           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-01-10 10:43:13 PST ---
This D2 program tries to sort in-place a dynamic array of Foo according to just
the first int x field (the third sort works on the whole structs), but when T
is a char the program doesn't compile:


import std.algorithm: sort, schwartzSort;
alias char T; // doesn't work
//alias int T; // works
struct Foo {
    int x;
    T[10] a;
}
void main() {
    auto array = new Foo[10];
    sort!("a.x > b.x")(array);
    static bool myComp(Foo f1, Foo f2) { return f1.x < f2.x; }
    sort!(myComp)(array);
    sort(array);
}



DMD 2.051 prints:
...\dmd\src\phobos\std\conv.d(99): Error: template std.conv.toImpl(T,S) if
(!implicitlyConverts!(S,T) && isSomeString!(T) && isInputRange!(Unqual!(S)) &&
isSomeChar!(ElementType!(S))) toImpl(T,S) if (!implicitlyConverts!(S,T) &&
isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S)))
matches more than one template declaration,
...\dmd\src\phobos\std\conv.d(114):toImpl(T,S) if (!implicitlyConverts!(S,T) &&
isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S)))
and ...\dmd\src\phobos\std\conv.d(224):toImpl(T,S) if (isStaticArray!(S))

-- 
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