sorting failed error

monarch_dodra monarchdodra at gmail.com
Mon Jul 30 12:08:45 PDT 2012


On Monday, 30 July 2012 at 18:50:24 UTC, bearophile wrote:
> maarten van damme:
>
>> Still my sorting problem isn't sorted out.
>
> Another possible cause: in D if you sort structs that contain 
> dynamic arrays, the actual contents of the arrays is ignored. 
> This is a HUGE bug in DMD.
>
> Bye,
> bearophile

Could you share the bug report? This works fine for me... :

----
import std.stdio;
import std.range;
import std.algorithm;
struct S
{
     int opCmp(S b)
     {
       if(v[0] < b.v[0]) return -1;
       if(v[0] > b.v[0]) return  1;
       return 0;
     }
     int[] v;
}

void main()
{
   S[3] ss;
   ss[0].v = [1, 2].array();
   ss[1].v = [5, 6].array();
   ss[2].v = [3, 4].array();
   writeln(ss[]);
   ss[].sort();
   writeln(ss[]);
}
----

Or did you mean something else?


More information about the Digitalmars-d-learn mailing list