std.algorithm.sort docu: use release to get the source back

This commit is contained in:
Sebastian Wilzbach 2016-04-19 04:46:09 +03:00
parent 4f18045c7f
commit 120b7a4a56

View file

@ -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
{