Bug 7246 – Provide a simpler example for std.algorithm.remove
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-01-07T23:25:00Z
Last change time
2014-08-18T15:52:40Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
jlquinn
Comments
Comment #0 by jlquinn — 2012-01-07T23:25:31Z
Example for remove with predicate is the following:
int[] a = [ 1, 2, 3, 2, 3, 4, 5, 2, 5, 6 ];
assert(a[0 .. remove!("a == 2")(a).length] == [ 1, 3, 3, 4, 5, 5, 6 ]);
This example is confusing because the array is named 'a' and the predicate placeholder is also named 'a'. Yes, reading the predicate blurb at the top says that 'a' is a predicate var, but if the example used 2 different names, it would at least alert the impatient reader about this assumption more clearly. I suggest:
int[] r = [ 1, 2, 3, 2, 3, 4, 5, 2, 5, 6 ];
assert(r[0 .. remove!("a == 2")(r).length] == [ 1, 3, 3, 4, 5, 5, 6 ]);
Comment #1 by andrej.mitrovich — 2014-04-23T12:02:05Z