mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
Merge pull request #4214 from wilzbach/sort_use_release
std.algorithm.sort docu: use release to get the source back
This commit is contained in:
commit
4b44f19180
1 changed files with 9 additions and 6 deletions
|
@ -1131,17 +1131,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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue