A.M. wrote:
Andrei Alexandrescu Wrote:
A.M. wrote:
import std.string;
import std.array;
import std.algorithm;
void main()
{
string[] sa = ["TOM","JOE","TOM4","TOM12","TOM6"];
sort!(comp)(sa);
}
bool comp(string x, string y)
{
string[] s = [x,y];
return isSorted(s);
}
this code compiles find, but when run gives the following error:
core.exception.asserter...@./../../src/phobos/std/array.d(210): Attempting to
fetch the front of an empty array
I'm using dmd2.030
same happens with dmd2.029
is that a bug?
The comp function must be an ordering function of the likes of "<", and
yours is a very expensive way to compute x <= y. Sort does not work with
"<=", only with "<".
Andrei
I actually changed it to:
return x<y
Did things work after that replacement? (Thanks for the bug report too,
regardless on whether it unveils an actual bug in std.algorithm.)
Andrei