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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 container->clear(); | 141 container->clear(); |
142 } | 142 } |
143 | 143 |
144 // Given an STL container consisting of (key, value) pairs, STLDeleteValues | 144 // Given an STL container consisting of (key, value) pairs, STLDeleteValues |
145 // deletes all the "value" components and clears the container. Does nothing | 145 // deletes all the "value" components and clears the container. Does nothing |
146 // in the case it's given a NULL pointer. | 146 // in the case it's given a NULL pointer. |
147 template <class T> | 147 template <class T> |
148 void STLDeleteValues(T* container) { | 148 void STLDeleteValues(T* container) { |
149 if (!container) | 149 if (!container) |
150 return; | 150 return; |
151 for (typename T::iterator i(container->begin()); i != container->end(); ++i) | 151 STLDeleteContainerPairSecondPointers(container->begin(), container->end()); |
152 delete i->second; | |
153 container->clear(); | 152 container->clear(); |
154 } | 153 } |
155 | 154 |
156 | 155 |
157 // The following classes provide a convenient way to delete all elements or | 156 // The following classes provide a convenient way to delete all elements or |
158 // values from STL containers when they goes out of scope. This greatly | 157 // values from STL containers when they goes out of scope. This greatly |
159 // simplifies code that creates temporary objects and has multiple return | 158 // simplifies code that creates temporary objects and has multiple return |
160 // statements. Example: | 159 // statements. Example: |
161 // | 160 // |
162 // vector<MyProto *> tmp_proto; | 161 // vector<MyProto *> tmp_proto; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 bool STLIncludes(const Arg1& a1, const Arg2& a2) { | 250 bool STLIncludes(const Arg1& a1, const Arg2& a2) { |
252 DCHECK(STLIsSorted(a1)); | 251 DCHECK(STLIsSorted(a1)); |
253 DCHECK(STLIsSorted(a2)); | 252 DCHECK(STLIsSorted(a2)); |
254 return std::includes(a1.begin(), a1.end(), | 253 return std::includes(a1.begin(), a1.end(), |
255 a2.begin(), a2.end()); | 254 a2.begin(), a2.end()); |
256 } | 255 } |
257 | 256 |
258 } // namespace base | 257 } // namespace base |
259 | 258 |
260 #endif // BASE_STL_UTIL_H_ | 259 #endif // BASE_STL_UTIL_H_ |
OLD | NEW |