Using array.sort
torhu
fake at address.dude
Wed Jan 24 09:55:30 PST 2007
Heinz wrote:
> What does this sort property do? how can i use it? how do i implement opCmp. thanks in advance
.sort sorts an array, using some default sort order. If you want to
change the order, you implement opCmp.
opCmp has got these signatures, think. It doesn't seem to be documented
much:
class C {
// the argument is of type Object, not C
int opCmp(Object other);
}
or:
struct S {
int opCmp(S other);
}
opCmp() has to return less than zero if it's own object is smaller, more
than zero if 'other' is smaller, and zero if they are equal.
You can't define opCmp for any other types, if you want to change the
sort order of ints, you have to write a separate sort function.
More information about the Digitalmars-d-learn
mailing list