mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 06:30:28 +03:00
Merge pull request #2107 from AndrejMitrovic/Fix7246
Issue 7246 - Provide a simpler example for std.algorithm.remove.
This commit is contained in:
commit
79903eb199
1 changed files with 14 additions and 2 deletions
|
@ -8744,8 +8744,20 @@ if (isBidirectionalRange!Range)
|
|||
///
|
||||
unittest
|
||||
{
|
||||
int[] a = [ 1, 2, 3, 2, 3, 4, 5, 2, 5, 6 ];
|
||||
assert(remove!("a == 2")(a) == [ 1, 3, 3, 4, 5, 5, 6 ]);
|
||||
static immutable base = [1, 2, 3, 2, 4, 2, 5, 2];
|
||||
|
||||
int[] arr = base[].dup;
|
||||
|
||||
// using a string-based predicate
|
||||
assert(remove!("a == 2")(arr) == [ 1, 3, 4, 5 ]);
|
||||
|
||||
// The original array contents have been modified,
|
||||
// so we need to reset it to its original state.
|
||||
// The length is unmodified however.
|
||||
arr[] = base[];
|
||||
|
||||
// using a lambda predicate
|
||||
assert(remove!(a => a == 2)(arr) == [ 1, 3, 4, 5 ]);
|
||||
}
|
||||
|
||||
unittest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue