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

Unified Diff: third_party/base/stl_util.h

Issue 1780063003: Move ScopedSetInsertion to third_party/base/stl_util.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 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 | « fpdfsdk/src/fpdfsave.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/base/stl_util.h
diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h
index 353d3a68c3353218ecb9396c8b6ea6fe2bb61e0a..2d1846724c3094161ce910986fd13be10c7b9f62 100644
--- a/third_party/base/stl_util.h
+++ b/third_party/base/stl_util.h
@@ -6,6 +6,7 @@
#define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_
#include <algorithm>
+#include <set>
#include "third_party/base/numerics/safe_conversions.h"
@@ -33,6 +34,22 @@ ResultType CollectionSize(const Collection& collection) {
return pdfium::base::checked_cast<ResultType, size_t>(collection.size());
}
+// Track the addition of an object to a set, removing it automatically when
+// the ScopedSetInsertion goes out of scope.
+template <typename T>
+class ScopedSetInsertion {
+ public:
+ ScopedSetInsertion(std::set<T>* org_set, T elem)
+ : m_Set(org_set), m_Entry(elem) {
+ m_Set->insert(m_Entry);
+ }
+ ~ScopedSetInsertion() { m_Set->erase(m_Entry); }
+
+ private:
+ std::set<T>* const m_Set;
+ const T m_Entry;
+};
+
} // namespace pdfium
#endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_
« no previous file with comments | « fpdfsdk/src/fpdfsave.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698