Skip to content

Commit

Permalink
std.algorithm.sort docu: use release to get the source back
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Apr 20, 2016
1 parent 4f18045 commit 120b7a4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions std/algorithm/sorting.d
Original file line number Diff line number Diff line change
Expand Up @@ -1062,17 +1062,20 @@ sort(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
@safe pure nothrow unittest
{
int[] array = [ 1, 2, 3, 4 ];

// sort in descending order
sort!("a > b")(array);
array.sort!("a > b");
assert(array == [ 4, 3, 2, 1 ]);

// sort in ascending order
sort(array);
array.sort();
assert(array == [ 1, 2, 3, 4 ]);
// sort with a delegate
bool myComp(int x, int y) @safe pure nothrow { return x > y; }
sort!(myComp)(array);
assert(array == [ 4, 3, 2, 1 ]);

// sort with reusable comparator and chain
alias myComp = (x, y) => x > y;
assert(array.sort!(myComp).release == [ 4, 3, 2, 1 ]);
}

///
unittest
{
Expand Down

0 comments on commit 120b7a4

Please sign in to comment.