Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1799)

Unified Diff: base/stl_util.h

Issue 2457343002: Remove stl_util's STLDeleteContainerPointers. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/containers/scoped_ptr_hash_map.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « base/containers/scoped_ptr_hash_map.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698