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:
H. S. Teoh 2014-11-02 21:29:22 -08:00
commit 3bb4bb24d5

View file

@ -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 ]; int[] arr = [ 1, 2, 2, 2, 2, 3, 4, 4, 4, 5 ];
assert(equal(uniq(arr), [ 1, 2, 3, 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) private struct UniqResult(alias pred, Range)