summaryrefslogtreecommitdiffstats
path: root/Source/cmAlgorithms.h
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2015-02-15 17:58:36 (GMT)
committerStephen Kelly <steveire@gmail.com>2015-02-15 18:56:08 (GMT)
commit050958a3286f69c577fe5d03407800cbe0367898 (patch)
treef7a03c16b84a6848cbd2b5665c19d4f7b2bf7b65 /Source/cmAlgorithms.h
parenta77af8f1301b6a9964c187ffff7a1893a80fbe90 (diff)
downloadCMake-050958a3286f69c577fe5d03407800cbe0367898.zip
CMake-050958a3286f69c577fe5d03407800cbe0367898.tar.gz
CMake-050958a3286f69c577fe5d03407800cbe0367898.tar.bz2
cmAlgorithms: Add cmRemoveMatching algorithm.
Implement it in terms of std::remove_if with a binary search through a matching range.
Diffstat (limited to 'Source/cmAlgorithms.h')
-rw-r--r--Source/cmAlgorithms.h24
1 files changed, 24 insertions, 0 deletions
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<typename Range>
+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<typename Iter1, typename Iter2>
@@ -226,4 +243,11 @@ typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem)
return writer;
}
+template<typename Range, typename MatchRange>
+typename Range::const_iterator cmRemoveMatching(Range &r, MatchRange const& m)
+{
+ return std::remove_if(r.begin(), r.end(),
+ ContainerAlgorithms::BinarySearcher<MatchRange>(m));
+}
+
#endif