From 41e17aa0c7b382c05279c41abe8b2af707df6d1d Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Tue, 8 Sep 2015 14:55:45 +0000 Subject: [PATCH] Add CSequence::removeIfIn(const CSequence &other) Remove all elements if they are in other --- src/blackmisc/sequence.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/blackmisc/sequence.h b/src/blackmisc/sequence.h index 80e4b37ca..33ccd2473 100644 --- a/src/blackmisc/sequence.h +++ b/src/blackmisc/sequence.h @@ -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.