January 10, 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@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@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: -------
April 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5442



--- Comment #2 from SomeDude <lovelydear@mailmetrash.com> 2012-04-22 14:59:01 PDT ---
(In reply to comment #1)
> (but doesn't run as I
> expected, though), due to this :
> import std.stdio;
> 
> struct Foo {
>     int x;
>     this(int x){this.x = x;}
> }
> void main() {
>     auto array = new Foo[10];
>     //for(int i = array.length; i > 1; i--) { array[i].x = i; }
>     auto i = array.length;
>     foreach(Foo f; array) { f.x = --i; write(f.x);}
>     writeln();
>     foreach(Foo f; array) { write(f.x);}
> }
> 
> giving that:
> PS E:\DigitalMars\dmd2\samples> rdmd -O bug.d
> 9876543210
> 0000000000

Never mind this part of the message, it's wrong code.

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