Menu

#7 Invalid removing using RemoveIf

open
nobody
Algorithms (3)
5
2003-01-22
2003-01-22
No

Arrgh ! Removing items from collections is so difficult !

I tried using RemoveIf algorithm and got wrong answer
Items weren't removed at all

After dwelving into code I found a bug

RemoveIf(container,test) calls
RemoveIfIn(start,finish,test) that
in turn call FindIfIn to find first occurence of the
item to delete and then removeCopyIfIn(s, _end, s,
test) to remove remaining items

BUT when you look into removeCopyIfIn you find that

if test(o^) then
begin
_output(dest, o^);
end;

So items that verifies test are copied which is not
expected
behavior !

Solution : add a "not" in front of test(o^) if it does
not break standalone call of removeCopyIfIn

Please forgive my bad english.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB