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 29 matching lines...) Expand all Loading... |
40 // stale pointer. | 40 // stale pointer. |
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 | |
51 // the FIRST item in the pairs. | |
52 // NOTE: Like STLDeleteContainerPointers, deleting behind the iterator. | |
53 template <class ForwardIterator> | |
54 void STLDeleteContainerPairFirstPointers(ForwardIterator begin, | |
55 ForwardIterator end) { | |
56 while (begin != end) { | |
57 ForwardIterator temp = begin; | |
58 ++begin; | |
59 delete temp->first; | |
60 } | |
61 } | |
62 | |
63 // For a range within a container of pairs, calls delete. | 50 // For a range within a container of pairs, calls delete. |
64 // NOTE: Like STLDeleteContainerPointers, deleting behind the iterator. | 51 // NOTE: Like STLDeleteContainerPointers, deleting behind the iterator. |
65 // Deleting the value does not always invalidate the iterator, but it may | 52 // Deleting the value does not always invalidate the iterator, but it may |
66 // do so if the key is a pointer into the value object. | 53 // do so if the key is a pointer into the value object. |
67 template <class ForwardIterator> | 54 template <class ForwardIterator> |
68 void STLDeleteContainerPairSecondPointers(ForwardIterator begin, | 55 void STLDeleteContainerPairSecondPointers(ForwardIterator begin, |
69 ForwardIterator end) { | 56 ForwardIterator end) { |
70 while (begin != end) { | 57 while (begin != end) { |
71 ForwardIterator temp = begin; | 58 ForwardIterator temp = begin; |
72 ++begin; | 59 ++begin; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 bool STLIncludes(const Arg1& a1, const Arg2& a2) { | 210 bool STLIncludes(const Arg1& a1, const Arg2& a2) { |
224 DCHECK(STLIsSorted(a1)); | 211 DCHECK(STLIsSorted(a1)); |
225 DCHECK(STLIsSorted(a2)); | 212 DCHECK(STLIsSorted(a2)); |
226 return std::includes(a1.begin(), a1.end(), | 213 return std::includes(a1.begin(), a1.end(), |
227 a2.begin(), a2.end()); | 214 a2.begin(), a2.end()); |
228 } | 215 } |
229 | 216 |
230 } // namespace base | 217 } // namespace base |
231 | 218 |
232 #endif // BASE_STL_UTIL_H_ | 219 #endif // BASE_STL_UTIL_H_ |
OLD | NEW |