www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5854] New: Built-in array sort doesn't sort SysTime

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5854

           Summary: Built-in array sort doesn't sort SysTime
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: Jesse.K.Phillips+D gmail.com
                CC: Jesse.K.Phillips+D gmail.com



11:23:02 PDT ---
This could be related to Issue 5853, Sorting SysTime: overlapping array copy.
But I didn't see anything obviously wrong with SysTime.

import std.datetime;

void main() {
    auto arr = [
        SysTime(DateTime(2011,4,4)),
        SysTime(DateTime(2011,3,22))
        ];
    auto ans = [
        SysTime(DateTime(2011,3,22)),
        SysTime(DateTime(2011,4,4))
        ];
    arr.sort;
    assert(arr == ans);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 18 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5854


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
         OS/Version|Windows                     |All



It does sort the array, but not correctly, e.g.

-----------------------------------------
import std.datetime, std.stdio;
void main() {
    auto arr = [
        SysTime(DateTime(2011,4,4)),
        SysTime(DateTime(2011,1,2)),
        SysTime(DateTime(2011,2,9)),
        SysTime(DateTime(2011,3,22))];
    writeln(arr);
    arr.sort;
    writeln(arr);
}
-----------------------------------------

prints

[2011-Apr-04 00:00:00, 2011-Jan-02 00:00:00, 2011-Feb-09 00:00:00, 2011-Mar-22
00:00:00]
[2011-Jan-02 00:00:00, 2011-Apr-04 00:00:00, 2011-Mar-22 00:00:00, 2011-Feb-09
00:00:00]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 18 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5854


kekeniro2 yahoo.co.jp changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kekeniro2 yahoo.co.jp
          Component|DMD                         |Phobos



The cause is in Phobos library.(std.datetime)
Struct SysTime has some opCmp, but lacks the required one to overload.

http://dlang.org/arrays.html#array-properties
 For the .sort property to work on arrays of structs or unions, the struct or
union definition must define the function: int opCmp(ref const S) const. The
type S is the type of the struct or union. This function will determine the
sort ordering.
-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 17 2012