summaryrefslogtreecommitdiff
path: root/shared/stl_tools.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:14:37 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:14:37 +0200
commit8bf668665b107469086f16cb8ad23e47d479d2b4 (patch)
tree66a91ef06a8caa7cd6819dcbe1860693d3eda8d5 /shared/stl_tools.h
parent3.21 (diff)
downloadFreeFileSync-8bf668665b107469086f16cb8ad23e47d479d2b4.tar.gz
FreeFileSync-8bf668665b107469086f16cb8ad23e47d479d2b4.tar.bz2
FreeFileSync-8bf668665b107469086f16cb8ad23e47d479d2b4.zip
4.0
Diffstat (limited to 'shared/stl_tools.h')
-rw-r--r--shared/stl_tools.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/shared/stl_tools.h b/shared/stl_tools.h
new file mode 100644
index 00000000..6cfe35f8
--- /dev/null
+++ b/shared/stl_tools.h
@@ -0,0 +1,49 @@
+// **************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
+// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) *
+// **************************************************************************
+
+#ifndef STL_TOOLS_HEADER_84567184321434
+#define STL_TOOLS_HEADER_84567184321434
+
+//no need to drag in any STL includes :)
+
+namespace zen
+{
+template <class V, class Predicate> inline
+void vector_remove_if(V& vec, Predicate p)
+{
+ vec.erase(std::remove_if(vec.begin(), vec.end(), p), vec.end());
+}
+
+
+template <class S, class Predicate> inline
+void set_remove_if(S& set, Predicate p)
+{
+ for (auto iter = set.begin(); iter != set.end();)
+ if (p(*iter))
+ set.erase(iter++);
+ else
+ ++iter;
+}
+
+
+template <class M, class Predicate> inline
+void map_remove_if(M& map, Predicate p) { set_remove_if(map, p); }
+
+
+// binary search returning an iterator
+template <class ForwardIterator, class T, typename Compare> inline
+ForwardIterator custom_binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp)
+{
+ first = std::lower_bound(first, last, value, comp);
+ if (first != last && !comp(value, *first))
+ return first;
+ else
+ return last;
+}
+}
+
+
+#endif //STL_TOOLS_HEADER_84567184321434 \ No newline at end of file
bgstack15