This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 1/6] add auto_sbitmap class
- From: tbsaunde+gcc at tbsaunde dot org
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 24 Jul 2016 07:44:44 -0400
- Subject: [PATCH 1/6] add auto_sbitmap class
- Authentication-results: sourceware.org; auth=none
- References: <20160724114449.12008-1-tbsaunde+gcc@tbsaunde.org>
From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
gcc/ChangeLog:
2016-07-24 Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
* sbitmap.h (auto_sbitmap): New class.
---
gcc/sbitmap.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/gcc/sbitmap.h b/gcc/sbitmap.h
index c208171..d4a2918 100644
--- a/gcc/sbitmap.h
+++ b/gcc/sbitmap.h
@@ -256,4 +256,25 @@ extern int bitmap_last_set_bit (const_sbitmap);
extern void debug_bitmap (const_sbitmap);
extern sbitmap sbitmap_realloc (sbitmap, unsigned int);
+
+/* a class that ties the lifetime of a sbitmap to its scope. */
+class auto_sbitmap
+{
+public:
+ explicit auto_sbitmap (unsigned int size) :
+ m_bitmap (sbitmap_alloc (size)) {}
+ ~auto_sbitmap () { sbitmap_free (m_bitmap); }
+
+ /* Allow calling sbitmap functions on our bitmap. */
+ operator sbitmap () { return m_bitmap; }
+
+private:
+ /* Prevent making a copy that refers to our sbitmap. */
+ auto_sbitmap (const auto_sbitmap &);
+ auto_sbitmap &operator = (const auto_sbitmap &);
+
+ /* The bitmap we are managing. */
+ sbitmap m_bitmap;
+};
+
#endif /* ! GCC_SBITMAP_H */
--
2.9.0