Chromium Code Reviews| Index: base/stl_util.h |
| diff --git a/base/stl_util.h b/base/stl_util.h |
| index 4159d8524a3f7e24d7d9101daae9d2d27b1d99a3..040579bba35bf17661d447d7f474d5b386e69887 100644 |
| --- a/base/stl_util.h |
| +++ b/base/stl_util.h |
| @@ -29,24 +29,6 @@ void STLClearObject(T* obj) { |
| obj->reserve(0); |
| } |
| -// For a range within a container of pointers, calls delete (non-array version) |
| -// on these pointers. |
| -// NOTE: for these three functions, we could just implement a DeleteObject |
| -// functor and then call for_each() on the range and functor, but this |
| -// requires us to pull in all of algorithm.h, which seems expensive. |
| -// For hash_[multi]set, it is important that this deletes behind the iterator |
| -// because the hash_set may call the hash function on the iterator when it is |
| -// advanced, which could result in the hash function trying to deference a |
| -// stale pointer. |
| -template <class ForwardIterator> |
| -void STLDeleteContainerPointers(ForwardIterator begin, ForwardIterator end) { |
| - while (begin != end) { |
| - ForwardIterator temp = begin; |
| - ++begin; |
| - delete *temp; |
| - } |
| -} |
| - |
| // Counts the number of instances of val in a container. |
| template <typename Container, typename T> |
| typename std::iterator_traits< |
| @@ -85,7 +67,14 @@ template <class T> |
| void STLDeleteElements(T* container) { |
| if (!container) |
| return; |
| - STLDeleteContainerPointers(container->begin(), container->end()); |
| + |
| + auto it = container->begin(); |
| + while (it != container->end()) { |
|
Mark Mentovai
2016/10/31 19:52:02
for would be more concise by one line.
Avi (use Gerrit)
2016/10/31 21:17:40
Is the issue of not being able to advance the iter
|
| + auto temp = it; |
| + ++it; |
| + delete *temp; |
| + } |
| + |
| container->clear(); |
| } |