[Issue 5442] std.algorithm.sort problem with struct with char[10]
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Dec 27 11:07:34 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=5442
Xinok <xinok at live.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xinok at live.com
--- Comment #3 from Xinok <xinok at live.com> 2013-12-27 11:07:29 PST ---
(In reply to comment #0)
> This D2 program tries to sort in-place a dynamic array of Foo according to just
> the first int x field (the third sort works on the whole structs), but when T
> is a char the program doesn't compile:
>
>
> import std.algorithm: sort, schwartzSort;
> alias char T; // doesn't work
> //alias int T; // works
> struct Foo {
> int x;
> T[10] a;
> }
> void main() {
> auto array = new Foo[10];
> sort!("a.x > b.x")(array);
> static bool myComp(Foo f1, Foo f2) { return f1.x < f2.x; }
> sort!(myComp)(array);
> sort(array);
> }
>
Tested in DMD 2.064.2 and I'm unable to reproduce the bug. The final line fails
to compile because Foo doesn't define opCmp, but everything else is fine. The
default predicate for sort is "a < b" and comparing two structs using less-than
requires defining opCmp.
Unless somebody else can reproduce this issue, I think we can close this bug
report.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list