View source code
Display the source code in std/algorithm/sorting.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Template std.algorithm.sorting.multiSort
void
multiSort
(Range)(Range r)
if (validPredicates!(ElementType!Range, less));
Sorts a range by multiple keys. The call
sorts the range multiSort
!("a.id < b.id",
"a.date > b.date")(r)r
by id
ascending,
and sorts elements that have the same id
by date
descending. Such a call is equivalent to
, but sort
!"a.id != b.id ? a.id
< b.id : a.date > b.date"(r)
is faster because it
does fewer comparisons (in addition to being more convenient).
multiSort
Arguments
template multiSort(less...);
Functions
Function name | Description |
---|---|
multiSort |
Example
static struct Point { int x, y; } auto pts1 = [ Point(0, 0), Point(5, 5), Point(0, 1), Point(0, 2) ]; auto pts2 = [ Point(0, 0), Point(0, 1), Point(0, 2), Point(5, 5) ]; multiSort!("a.x < b.x", "a.y < b.y", SwapStrategy.unstable)(pts1); assert(pts1 == pts2);