mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 15:40:36 +03:00
Merge pull request #2653 from CyberShadow/pull-20141102-104501
std.algorithm: Add a small neat in-place example for uniq
This commit is contained in:
commit
3bb4bb24d5
1 changed files with 4 additions and 0 deletions
|
@ -4298,6 +4298,10 @@ if (isInputRange!Range && is(typeof(binaryFun!pred(r.front, r.front)) == bool))
|
|||
{
|
||||
int[] arr = [ 1, 2, 2, 2, 2, 3, 4, 4, 4, 5 ];
|
||||
assert(equal(uniq(arr), [ 1, 2, 3, 4, 5 ][]));
|
||||
|
||||
// Filter duplicates in-place using copy
|
||||
arr.length -= arr.uniq().copy(arr).length;
|
||||
assert(arr == [ 1, 2, 3, 4, 5 ]);
|
||||
}
|
||||
|
||||
private struct UniqResult(alias pred, Range)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue