Chromium Code Reviews| 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. |