Chromium Code Reviews| Index: base/stl_util.h |
| diff --git a/base/stl_util.h b/base/stl_util.h |
| index b8683377bb7872c711c4bc5bef21a19db87bcf29..4159d8524a3f7e24d7d9101daae9d2d27b1d99a3 100644 |
| --- a/base/stl_util.h |
| +++ b/base/stl_util.h |
| @@ -47,20 +47,6 @@ void STLDeleteContainerPointers(ForwardIterator begin, ForwardIterator end) { |
| } |
| } |
| -// For a range within a container of pairs, calls delete. |
| -// NOTE: Like STLDeleteContainerPointers, deleting behind the iterator. |
| -// Deleting the value does not always invalidate the iterator, but it may |
| -// do so if the key is a pointer into the value object. |
| -template <class ForwardIterator> |
| -void STLDeleteContainerPairSecondPointers(ForwardIterator begin, |
| - ForwardIterator end) { |
| - while (begin != end) { |
| - ForwardIterator temp = begin; |
| - ++begin; |
| - delete temp->second; |
| - } |
| -} |
|
Nico
2016/09/22 15:56:11
The usual comment: I"d put this bit in a separate
Avi (use Gerrit)
2016/09/22 19:17:16
Done.
|
| - |
| // Counts the number of instances of val in a container. |
| template <typename Container, typename T> |
| typename std::iterator_traits< |
| @@ -110,7 +96,14 @@ template <class T> |
| void STLDeleteValues(T* container) { |
| if (!container) |
| return; |
| - STLDeleteContainerPairSecondPointers(container->begin(), container->end()); |
| + |
| + auto it = container->begin(); |
| + while (it != container->end()) { |
| + auto temp = it; |
| + ++it; |
| + delete temp->second; |
| + } |
| + |
| container->clear(); |
| } |