| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 container->clear(); | 103 container->clear(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Given an STL container consisting of (key, value) pairs, STLDeleteValues | 106 // Given an STL container consisting of (key, value) pairs, STLDeleteValues |
| 107 // deletes all the "value" components and clears the container. Does nothing | 107 // deletes all the "value" components and clears the container. Does nothing |
| 108 // in the case it's given a NULL pointer. | 108 // in the case it's given a NULL pointer. |
| 109 template <class T> | 109 template <class T> |
| 110 void STLDeleteValues(T* container) { | 110 void STLDeleteValues(T* container) { |
| 111 if (!container) | 111 if (!container) |
| 112 return; | 112 return; |
| 113 STLDeleteContainerPairSecondPointers(container->begin(), container->end()); | 113 |
| 114 auto it = container->begin(); |
| 115 while (it != container->end()) { |
| 116 auto temp = it; |
| 117 ++it; |
| 118 delete temp->second; |
| 119 } |
| 120 |
| 114 container->clear(); | 121 container->clear(); |
| 115 } | 122 } |
| 116 | 123 |
| 117 // Test to see if a set, map, hash_set or hash_map contains a particular key. | 124 // Test to see if a set, map, hash_set or hash_map contains a particular key. |
| 118 // Returns true if the key is in the collection. | 125 // Returns true if the key is in the collection. |
| 119 template <typename Collection, typename Key> | 126 template <typename Collection, typename Key> |
| 120 bool ContainsKey(const Collection& collection, const Key& key) { | 127 bool ContainsKey(const Collection& collection, const Key& key) { |
| 121 return collection.find(key) != collection.end(); | 128 return collection.find(key) != collection.end(); |
| 122 } | 129 } |
| 123 | 130 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 bool STLIncludes(const Arg1& a1, const Arg2& a2) { | 189 bool STLIncludes(const Arg1& a1, const Arg2& a2) { |
| 183 DCHECK(STLIsSorted(a1)); | 190 DCHECK(STLIsSorted(a1)); |
| 184 DCHECK(STLIsSorted(a2)); | 191 DCHECK(STLIsSorted(a2)); |
| 185 return std::includes(a1.begin(), a1.end(), | 192 return std::includes(a1.begin(), a1.end(), |
| 186 a2.begin(), a2.end()); | 193 a2.begin(), a2.end()); |
| 187 } | 194 } |
| 188 | 195 |
| 189 } // namespace base | 196 } // namespace base |
| 190 | 197 |
| 191 #endif // BASE_STL_UTIL_H_ | 198 #endif // BASE_STL_UTIL_H_ |
| OLD | NEW |