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

Unified Diff: base/stl_util.h

Issue 1010973013: Refactor Uses of std::set to std::vector in SimpleFeature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove Unsigned From Checks with STLCount Created 5 years, 9 months 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 | chrome/browser/content_settings/content_settings_internal_extension_provider.cc » ('j') | 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 89a53b070ef515cf81d584098e7aace8ed2ba201..e937d2f3ed9157d433cc62fb71958bd9c71cd6d9 100644
--- a/base/stl_util.h
+++ b/base/stl_util.h
@@ -90,6 +90,14 @@ void STLDeleteContainerPairSecondPointers(ForwardIterator begin,
}
}
+// Counts the number of instances of val in a container.
+template <typename Container, typename T>
+typename std::iterator_traits<
+ typename Container::const_iterator>::difference_type
+STLCount(const Container& container, const T& val) {
+ return std::count(container.begin(), container.end(), val);
+}
+
// To treat a possibly-empty vector as an array, use these functions.
// If you know the array will never be empty, you can use &*v.begin()
// directly, but that is undefined behaviour if |v| is empty.
@@ -195,6 +203,14 @@ bool ContainsKey(const Collection& collection, const Key& key) {
return collection.find(key) != collection.end();
}
+// Test to see if a collection like a vector contains a particular value.
+// Returns true if the value is in the collection.
+template <typename Collection, typename Value>
+bool ContainsValue(const Collection& collection, const Value& value) {
tfarina 2015/04/03 01:26:37 why these and the above functions were not added t
robliao 2015/04/03 17:15:31 Consistency was the major driving factor. Contains
+ return std::find(collection.begin(), collection.end(), value) !=
+ collection.end();
+}
+
namespace base {
// Returns true if the container is sorted.
« no previous file with comments | « no previous file | chrome/browser/content_settings/content_settings_internal_extension_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698