summaryrefslogtreecommitdiff
path: root/third_party/base/stl_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/base/stl_util.h')
-rw-r--r--third_party/base/stl_util.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h
index 353d3a68c3..2d1846724c 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_