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

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: add tests 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
Index: base/stl_util.h
diff --git a/base/stl_util.h b/base/stl_util.h
index b3ddfa3b4fe8f85bb9568768d1a2af9fd7c75d19..d5c8873e7fee512e06ed944382d6b27f868d6b70 100644
--- a/base/stl_util.h
+++ b/base/stl_util.h
@@ -7,6 +7,7 @@
#ifndef BASE_STL_UTIL_H_
#define BASE_STL_UTIL_H_
+#include <algorithm>
#include <string>
#include <vector>
@@ -191,4 +192,15 @@ bool ContainsKey(const Collection& collection, const Key& key) {
return collection.find(key) != collection.end();
}
willchan no longer on Chromium 2012/12/01 17:22:13 New code should go into the base namespace. I know
tfarina 2012/12/01 17:24:19 I tried to do this incrementally, but you wanted m
willchan no longer on Chromium 2012/12/01 17:38:45 If I'm being inconsistent, that's bad. Are you sur
not at google - send to devlin 2012/12/03 20:22:01 I'll put this in base.
+// Returns a new std::set containing the difference of two sets.
willchan no longer on Chromium 2012/12/01 17:22:13 It does not necessarily return a new std::set. Ple
+// A convenient wrapper around std::set_difference.
+template <typename ResultType, typename Arg1, typename Arg2>
+ResultType STLSetDifference(const Arg1& a1, const Arg2& a2) {
+ ResultType difference;
+ std::set_difference(a1.begin(), a1.end(),
willchan no longer on Chromium 2012/12/01 17:22:13 Jeffrey alluded to it earlier, but the part that w
not at google - send to devlin 2012/12/03 20:22:01 Discussing this with willchan a bit, and it's a bi
Jeffrey Yasskin 2012/12/03 20:29:35 template<typename Container> bool is_sorted(const
not at google - send to devlin 2012/12/03 20:39:10 Dunno, I don't have stl in my veins. But cool, I c
+ a2.begin(), a2.end(),
+ std::inserter(difference, difference.end()));
+ return difference;
+}
+
#endif // BASE_STL_UTIL_H_
« no previous file with comments | « base/base.gyp ('k') | base/stl_util_unittest.cc » ('j') | base/stl_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698