| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Derived from google3/util/gtl/stl_util.h | 5 // Derived from google3/util/gtl/stl_util.h |
| 6 | 6 |
| 7 #ifndef BASE_STL_UTIL_H_ | 7 #ifndef BASE_STL_UTIL_H_ |
| 8 #define BASE_STL_UTIL_H_ | 8 #define BASE_STL_UTIL_H_ |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // Returns true if the key is in the collection. | 80 // Returns true if the key is in the collection. |
| 81 template <typename Collection, typename Key> | 81 template <typename Collection, typename Key> |
| 82 bool ContainsKey(const Collection& collection, const Key& key) { | 82 bool ContainsKey(const Collection& collection, const Key& key) { |
| 83 return collection.find(key) != collection.end(); | 83 return collection.find(key) != collection.end(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Test to see if a collection like a vector contains a particular value. | 86 // Test to see if a collection like a vector contains a particular value. |
| 87 // Returns true if the value is in the collection. | 87 // Returns true if the value is in the collection. |
| 88 template <typename Collection, typename Value> | 88 template <typename Collection, typename Value> |
| 89 bool ContainsValue(const Collection& collection, const Value& value) { | 89 bool ContainsValue(const Collection& collection, const Value& value) { |
| 90 return std::find(collection.begin(), collection.end(), value) != | 90 return std::find(std::begin(collection), std::end(collection), value) != |
| 91 collection.end(); | 91 std::end(collection); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Returns true if the container is sorted. | 94 // Returns true if the container is sorted. |
| 95 template <typename Container> | 95 template <typename Container> |
| 96 bool STLIsSorted(const Container& cont) { | 96 bool STLIsSorted(const Container& cont) { |
| 97 // Note: Use reverse iterator on container to ensure we only require | 97 // Note: Use reverse iterator on container to ensure we only require |
| 98 // value_type to implement operator<. | 98 // value_type to implement operator<. |
| 99 return std::adjacent_find(cont.rbegin(), cont.rend(), | 99 return std::adjacent_find(cont.rbegin(), cont.rend(), |
| 100 std::less<typename Container::value_type>()) | 100 std::less<typename Container::value_type>()) |
| 101 == cont.rend(); | 101 == cont.rend(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 class Allocator, | 283 class Allocator, |
| 284 class Predicate> | 284 class Predicate> |
| 285 void EraseIf(std::unordered_multiset<Key, Hash, KeyEqual, Allocator>& container, | 285 void EraseIf(std::unordered_multiset<Key, Hash, KeyEqual, Allocator>& container, |
| 286 Predicate pred) { | 286 Predicate pred) { |
| 287 internal::IterateAndEraseIf(container, pred); | 287 internal::IterateAndEraseIf(container, pred); |
| 288 } | 288 } |
| 289 | 289 |
| 290 } // namespace base | 290 } // namespace base |
| 291 | 291 |
| 292 #endif // BASE_STL_UTIL_H_ | 292 #endif // BASE_STL_UTIL_H_ |
| OLD | NEW |