Author: | ks |
---|---|
Mode: | text |
Date: | Mon, 18 Apr 2011 12:20:41 |
record WithLesser[T, F](x:T); [T,F] overload lesser?(a:WithLesser[T,F], b:WithLesser[T,F]) = F(a.x, b.x); [S, LesserComparator] sortBy(sequence:S, static LesserComparator) { alias T = SequenceElementType(S); sort(mapped( x => ref Pointer[WithLesser[T, LesserComparator]](&x)^, sequence, )); } main() { var a = [1, 2, 3, 4, 5]; sortBy(a, (x, y) => (-x < -y)); println(a); }