summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-12-09 10:43:40 +0100
committerMattes D <github@xoft.cz>2014-12-09 10:43:40 +0100
commit2ab8d2bd98004e40a915e1c9eca764d32115d6c5 (patch)
treeaacb80c32b8b2c1d9c3cfdb7750175dc8761c6ff
parentMerge pull request #1563 from mc-server/c++11Events (diff)
downloadcuberite-2ab8d2bd98004e40a915e1c9eca764d32115d6c5.tar
cuberite-2ab8d2bd98004e40a915e1c9eca764d32115d6c5.tar.gz
cuberite-2ab8d2bd98004e40a915e1c9eca764d32115d6c5.tar.bz2
cuberite-2ab8d2bd98004e40a915e1c9eca764d32115d6c5.tar.lz
cuberite-2ab8d2bd98004e40a915e1c9eca764d32115d6c5.tar.xz
cuberite-2ab8d2bd98004e40a915e1c9eca764d32115d6c5.tar.zst
cuberite-2ab8d2bd98004e40a915e1c9eca764d32115d6c5.zip
-rw-r--r--src/OSSupport/Queue.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h
index 8d096fe29..82f221453 100644
--- a/src/OSSupport/Queue.h
+++ b/src/OSSupport/Queue.h
@@ -163,6 +163,29 @@ public:
return false;
}
+
+ /** Removes all items for which the predicate returns true. */
+ template <class Predicate>
+ void RemoveIf(Predicate a_Predicate)
+ {
+ cCSLock Lock(m_CS);
+ for (auto itr = m_Contents.begin(); itr != m_Contents.end();)
+ {
+ if (a_Predicate(*itr))
+ {
+ auto itr2 = itr;
+ ++itr2;
+ m_Contents.erase(itr);
+ m_evtRemoved.Set();
+ itr = itr2;
+ }
+ else
+ {
+ ++itr;
+ }
+ } // for itr - m_Contents[]
+ }
+
private:
/// The contents of the queue
QueueType m_Contents;