[Issue 1309] sorting arrays of structs is broken

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 12 02:39:50 PDT 2011


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


Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |k.hara.pg at gmail.com
         Resolution|                            |FIXED


--- Comment #8 from Kenji Hara <k.hara.pg at gmail.com> 2011-04-12 02:36:01 PDT ---
On trunk dmd, this code works. 

----
import std.stdio;
import std.random;

struct MyStruct
{
    uint field;

    //int opCmp(MyStruct* m)
    int opCmp(ref const(MyStruct) m) const
    {
        writeln("This is opCmp");
        return field - m.field;
    }
}

void main()
{
    MyStruct[] structs;
    for(int i=0;i<50;i++)
        structs ~= MyStruct(50-i);

    structs.sort;

    foreach(s;structs)
        writeln(s.field);
}

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