Skip to content

Commit

Permalink
std.algorithm: Add a small neat in-place example for uniq
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Nov 2, 2014
1 parent af0629e commit 90bf9dc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions std/algorithm.d
Original file line number Diff line number Diff line change
Expand Up @@ -4258,6 +4258,10 @@ unittest
{
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)
Expand Down

0 comments on commit 90bf9dc

Please sign in to comment.