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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // As of 2006-04, there is no standard-blessed way of getting a | 69 // As of 2006-04, there is no standard-blessed way of getting a |
70 // mutable reference to a string's internal buffer. However, issue 530 | 70 // mutable reference to a string's internal buffer. However, issue 530 |
71 // (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#530) | 71 // (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#530) |
72 // proposes this as the method. According to Matt Austern, this should | 72 // proposes this as the method. According to Matt Austern, this should |
73 // already work on all current implementations. | 73 // already work on all current implementations. |
74 inline char* string_as_array(std::string* str) { | 74 inline char* string_as_array(std::string* str) { |
75 // DO NOT USE const_cast<char*>(str->data()) | 75 // DO NOT USE const_cast<char*>(str->data()) |
76 return str->empty() ? NULL : &*str->begin(); | 76 return str->empty() ? NULL : &*str->begin(); |
77 } | 77 } |
78 | 78 |
79 // Test to see if a set, map, hash_set or hash_map contains a particular key. | 79 // Test to see if a set or map contains a particular key. |
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) { |
(...skipping 193 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 |