From 050958a3286f69c577fe5d03407800cbe0367898 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 15 Feb 2015 18:58:36 +0100 Subject: cmAlgorithms: Add cmRemoveMatching algorithm. Implement it in terms of std::remove_if with a binary search through a matching range. --- Source/cmAlgorithms.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 70fdff6..0f162a2 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -154,6 +154,23 @@ Iter RemoveN(Iter i1, Iter i2, size_t n) return ContainerAlgorithms::Rotate(i1, i1 + n, i2); } +template +struct BinarySearcher +{ + typedef typename Range::value_type argument_type; + BinarySearcher(Range const& r) + : m_range(r) + { + } + + bool operator()(argument_type const& item) + { + return std::binary_search(m_range.begin(), m_range.end(), item); + } +private: + Range const& m_range; +}; + } template @@ -226,4 +243,11 @@ typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem) return writer; } +template +typename Range::const_iterator cmRemoveMatching(Range &r, MatchRange const& m) +{ + return std::remove_if(r.begin(), r.end(), + ContainerAlgorithms::BinarySearcher(m)); +} + #endif -- cgit v0.12