std.algorithm.sort fails?
Jonathan M Davis
jmdavisprog at gmail.com
Wed Aug 4 02:34:32 PDT 2010
On Wednesday 04 August 2010 02:17:31 Johannes Pfau wrote:
> Hi, I'm trying to sort an array of strings exactly the way it's done in
> the docs, but I don't get the expected results:
>
> ----------------------------
> import std.algorithm;
> import std.stdio;
> import std.contracts;
>
> void main()
> {
> string[] arr = ["unions", "vars", "d_enum", "constructors",
> "d_alias", "all", "templates", "classes",
> "interfaces", "sections", "structs", "nested",
> "functions"];
>
> sort!("toupper(a) < toupper(b)", SwapStrategy.stable)(arr);
>
> foreach(string a; arr)
> {
> writeln(a);
> }
>
> enforce(arr != ["all", "classes", "functions", "constructors",
> "d_alias", "d_enum", "interfaces", "nested",
> "sections", "structs", "templates", "unions",
> "vars"]);
> }
> -----------------------------
>
> The enforcement fails. Can anyone reproduce this or is this even a known
> bug?
There appears to be a bug with regards to SwapStrategy.stable. If you don't pass
it a swap strategy it works just fine, but if you do, it fails.
I'm using svn snapshot 1751 of phobos, which is a few weeks old, and it fails an
assertion in sort() which is checking whether the range was sorted. I have no
idea if it's been fixed since then. I don't see a bug report for it in either
case.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list