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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 template<class T> | 148 template<class T> |
149 class STLElementDeleter { | 149 class STLElementDeleter { |
150 public: | 150 public: |
151 STLElementDeleter<T>(T* container) : container_(container) {} | 151 STLElementDeleter<T>(T* container) : container_(container) {} |
152 ~STLElementDeleter<T>() { STLDeleteElements(container_); } | 152 ~STLElementDeleter<T>() { STLDeleteElements(container_); } |
153 | 153 |
154 private: | 154 private: |
155 T* container_; | 155 T* container_; |
156 }; | 156 }; |
157 | 157 |
158 // Given a pointer to an STL container this class will delete all the value | |
159 // pointers when it goes out of scope. | |
160 template<class T> | |
161 class STLValueDeleter { | |
162 public: | |
163 STLValueDeleter<T>(T* container) : container_(container) {} | |
164 ~STLValueDeleter<T>() { STLDeleteValues(container_); } | |
165 | |
166 private: | |
167 T* container_; | |
168 }; | |
169 | |
170 // Test to see if a set, map, hash_set or hash_map contains a particular key. | 158 // Test to see if a set, map, hash_set or hash_map contains a particular key. |
171 // Returns true if the key is in the collection. | 159 // Returns true if the key is in the collection. |
172 template <typename Collection, typename Key> | 160 template <typename Collection, typename Key> |
173 bool ContainsKey(const Collection& collection, const Key& key) { | 161 bool ContainsKey(const Collection& collection, const Key& key) { |
174 return collection.find(key) != collection.end(); | 162 return collection.find(key) != collection.end(); |
175 } | 163 } |
176 | 164 |
177 // Test to see if a collection like a vector contains a particular value. | 165 // Test to see if a collection like a vector contains a particular value. |
178 // Returns true if the value is in the collection. | 166 // Returns true if the value is in the collection. |
179 template <typename Collection, typename Value> | 167 template <typename Collection, typename Value> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 bool STLIncludes(const Arg1& a1, const Arg2& a2) { | 223 bool STLIncludes(const Arg1& a1, const Arg2& a2) { |
236 DCHECK(STLIsSorted(a1)); | 224 DCHECK(STLIsSorted(a1)); |
237 DCHECK(STLIsSorted(a2)); | 225 DCHECK(STLIsSorted(a2)); |
238 return std::includes(a1.begin(), a1.end(), | 226 return std::includes(a1.begin(), a1.end(), |
239 a2.begin(), a2.end()); | 227 a2.begin(), a2.end()); |
240 } | 228 } |
241 | 229 |
242 } // namespace base | 230 } // namespace base |
243 | 231 |
244 #endif // BASE_STL_UTIL_H_ | 232 #endif // BASE_STL_UTIL_H_ |
OLD | NEW |