Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1929)

Unified Diff: base/stl_util.h

Issue 11415239: Add STLSetDifference to stl_util.h, because std::set_difference is extremely (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert change to url_index_private_data.cc Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/stl_util.h
diff --git a/base/stl_util.h b/base/stl_util.h
index b3ddfa3b4fe8f85bb9568768d1a2af9fd7c75d19..4e0826c5ffb3acd307e19d67239891fcc6ff8d33 100644
--- a/base/stl_util.h
+++ b/base/stl_util.h
@@ -7,6 +7,8 @@
#ifndef BASE_STL_UTIL_H_
#define BASE_STL_UTIL_H_
+#include <algorithm>
+#include <set>
#include <string>
#include <vector>
@@ -191,4 +193,15 @@ bool ContainsKey(const Collection& collection, const Key& key) {
return collection.find(key) != collection.end();
}
+// Returns a new std::set containing the difference of two sets.
+// A convenient wrapper around std::set_difference.
+template <typename T>
+std::set<T> STLSetDifference(const std::set<T>& a, const std::set<T>& b) {
Jeffrey Yasskin 2012/11/30 23:00:16 I agree with the decision to only provide one over
Jeffrey Yasskin 2012/11/30 23:06:21 I'm just being dumb. insert_iterator uses 'iter =
+ std::set<T> difference;
+ std::set_difference(a.begin(), a.end(),
+ b.begin(), b.end(),
+ std::inserter(difference, difference.end()));
+ return difference;
+}
+
#endif // BASE_STL_UTIL_H_
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698