IAIK/sweb

Bug ustl::remove_copy_if

fhirmann opened this issue · 2 comments

I found a bug in the implementation of ustl::remove_copy_if. This also affects the ustl::remove_if which is often used for erasing elements in containers.

The implementation should be:
Remove_copy_if copies elements from the range [first, last) to a range beginning at result, except that elements for which pred is true are not copied.

There is a missing negation at pred (*first) so the function should be:

inline OutputIterator remove_copy_if (InputIterator first, InputIterator last, OutputIterator result, Predicate pred)
{
  for (; first != last; ++first)
    if (!pred (*first))
      *result++ = *first;
  return result;
}

Thanks for your fast response.