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 30 matching lines...) Expand all Loading... |
41 template <class ForwardIterator> | 41 template <class ForwardIterator> |
42 void STLDeleteContainerPointers(ForwardIterator begin, ForwardIterator end) { | 42 void STLDeleteContainerPointers(ForwardIterator begin, ForwardIterator end) { |
43 while (begin != end) { | 43 while (begin != end) { |
44 ForwardIterator temp = begin; | 44 ForwardIterator temp = begin; |
45 ++begin; | 45 ++begin; |
46 delete *temp; | 46 delete *temp; |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 // For a range within a container of pairs, calls delete (non-array version) on | 50 // For a range within a container of pairs, calls delete (non-array version) on |
51 // BOTH items in the pairs. | |
52 // NOTE: Like STLDeleteContainerPointers, it is important that this deletes | |
53 // behind the iterator because if both the key and value are deleted, the | |
54 // container may call the hash function on the iterator when it is advanced, | |
55 // which could result in the hash function trying to dereference a stale | |
56 // pointer. | |
57 template <class ForwardIterator> | |
58 void STLDeleteContainerPairPointers(ForwardIterator begin, | |
59 ForwardIterator end) { | |
60 while (begin != end) { | |
61 ForwardIterator temp = begin; | |
62 ++begin; | |
63 delete temp->first; | |
64 delete temp->second; | |
65 } | |
66 } | |
67 | |
68 // For a range within a container of pairs, calls delete (non-array version) on | |
69 // the FIRST item in the pairs. | 51 // the FIRST item in the pairs. |
70 // NOTE: Like STLDeleteContainerPointers, deleting behind the iterator. | 52 // NOTE: Like STLDeleteContainerPointers, deleting behind the iterator. |
71 template <class ForwardIterator> | 53 template <class ForwardIterator> |
72 void STLDeleteContainerPairFirstPointers(ForwardIterator begin, | 54 void STLDeleteContainerPairFirstPointers(ForwardIterator begin, |
73 ForwardIterator end) { | 55 ForwardIterator end) { |
74 while (begin != end) { | 56 while (begin != end) { |
75 ForwardIterator temp = begin; | 57 ForwardIterator temp = begin; |
76 ++begin; | 58 ++begin; |
77 delete temp->first; | 59 delete temp->first; |
78 } | 60 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 bool STLIncludes(const Arg1& a1, const Arg2& a2) { | 235 bool STLIncludes(const Arg1& a1, const Arg2& a2) { |
254 DCHECK(STLIsSorted(a1)); | 236 DCHECK(STLIsSorted(a1)); |
255 DCHECK(STLIsSorted(a2)); | 237 DCHECK(STLIsSorted(a2)); |
256 return std::includes(a1.begin(), a1.end(), | 238 return std::includes(a1.begin(), a1.end(), |
257 a2.begin(), a2.end()); | 239 a2.begin(), a2.end()); |
258 } | 240 } |
259 | 241 |
260 } // namespace base | 242 } // namespace base |
261 | 243 |
262 #endif // BASE_STL_UTIL_H_ | 244 #endif // BASE_STL_UTIL_H_ |
OLD | NEW |