Ref T464 Implement removal of one sequence from another in O(n),

assuming that elements in both sequences are in the same order in both.
This commit is contained in:
Mat Sutcliffe
2018-12-11 17:12:09 +00:00
committed by Klaus Basan
parent 40ae7174a7
commit 71de01065b
4 changed files with 47 additions and 4 deletions

View File

@@ -321,6 +321,13 @@ namespace BlackMisc
return removeIf([&other](const T &v) { return other.contains(v); });
}
//! Remove all elements if they are in other
//! \pre All elements of other must be present in the same order in this.
void removeIfInSubset(const CSequence &other)
{
erase(BlackMisc::removeIfIn(begin(), end(), other.begin(), other.end()), end());
}
//! Replace elements matching the given element with a replacement.
//! \return The number of elements replaced.
int replace(const T &original, const T &replacement)