summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-07-17 17:02:09 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-07-17 17:02:28 (GMT)
commit1793fa416371365f7435f1946cc556cc14613821 (patch)
tree7b9283b62a318f926238c5075dcdc953cbc9be90
parent5adcba3ba42a0f7cfde8dfdf6aa6f322077c3744 (diff)
downloadswift-contrib-1793fa416371365f7435f1946cc556cc14613821.zip
swift-contrib-1793fa416371365f7435f1946cc556cc14613821.tar.bz2
Added PairFirstEquals.
-rw-r--r--Swiften/Base/Algorithm.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/Swiften/Base/Algorithm.h b/Swiften/Base/Algorithm.h
index b7459ed..4e68e70 100644
--- a/Swiften/Base/Algorithm.h
+++ b/Swiften/Base/Algorithm.h
@@ -71,18 +71,23 @@ namespace Swift {
for (typename C::iterator it = c.begin(); it != c.end(); ) {
if (p(*it)) {
c.erase(it++);
}
else {
++it;
}
}
}
+
+ template<typename C, typename P>
+ void eraseIfImpl(C& c, const P& p, VectorCategory) {
+ c.erase(std::remove_if(c.begin(), c.end(), p), c.end());
+ }
}
template<typename C, typename V>
void erase(C& container, const V& value) {
Detail::eraseImpl(container, value, typename Detail::ContainerTraits<C>::Category());
}
template<typename C, typename P>
void eraseIf(C& container, const P& predicate) {
@@ -109,18 +114,32 @@ namespace Swift {
void safeClear(Container& c) {
std::fill(c.begin(), c.end(), 0);
c.clear();
}
/*
* Functors
*/
template<typename K, typename V>
+ class PairFirstEquals {
+ public:
+ PairFirstEquals(const K& value) : value(value) {
+ }
+
+ bool operator()(const std::pair<K,V>& pair) const {
+ return pair.first == value;
+ }
+
+ private:
+ K value;
+ };
+
+ template<typename K, typename V>
class PairSecondEquals {
public:
PairSecondEquals(const V& value) : value(value) {
}
bool operator()(const std::pair<K,V>& pair) const {
return pair.second == value;
}