Add CSequence::removeIfIn(const CSequence &other)

Remove all elements if they are in other
This commit is contained in:
Roland Winklmeier
2015-09-08 14:55:45 +00:00
committed by Mathew Sutcliffe
parent a7b71d974b
commit 41e17aa0c7

View File

@@ -388,6 +388,20 @@ namespace BlackMisc
return count;
}
/*!
* \brief Remove all elements if they are in other
* \pre The sequence must be initialized.
* \return The number of elements removed.
*/
int removeIfIn(const CSequence &other)
{
auto newEnd = std::remove_if(begin(), end(), [&other](const T &v) { return other.contains(v); });
int count = std::distance(newEnd, end());
erase(newEnd, end());
return count;
}
/*!
* \brief Replace elements matching the given element with a replacement.
* \return The number of elements replaced.