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_ |