Comment #0 by Jesse.K.Phillips+D — 2011-04-18T11:23:02Z
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);
}
Comment #1 by kennytm — 2011-04-18T12:30:54Z
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]
Comment #2 by kekeniro2 — 2012-10-17T19:21:30Z
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.
# I have no idea whether DMD could print an error or not.