setIntersection of struct range

Jesse Phillips jessekphillips+d at gmail.com
Wed Aug 12 09:29:22 PDT 2009


Steven Schveighoffer Wrote:

> You did not define a way to compare two S structs.  Try redefining S like  
> this:
> 
> struct S {
>    string label;
>    int opCmp(ref const S s2) const {
>       if(label < s2.label)
>         return -1;
>       if(label > s2.label)
>         return 1;
>       return 0;
>    }
> }

You know, I didn't think about this because struct arrays are sorted by the first element if you do array.sort. But this does make the error a little more clear.


More information about the Digitalmars-d-learn mailing list