diff options
author | Trevor Saunders <tbsaunde+gcc@tbsaunde.org> | 2016-07-26 10:43:58 +0000 |
---|---|---|
committer | Trevor Saunders <tbsaunde@gcc.gnu.org> | 2016-07-26 10:43:58 +0000 |
commit | 62e2078514e307bc1b9fecff29977a5476fc7c45 (patch) | |
tree | 299a1eee3dbe30e13d670994cfbc8dd09e612ece | |
parent | 3ef7d2236b0f8cf6fbb52086343ef0728356f161 (diff) | |
download | gcc-62e2078514e307bc1b9fecff29977a5476fc7c45.zip gcc-62e2078514e307bc1b9fecff29977a5476fc7c45.tar.gz gcc-62e2078514e307bc1b9fecff29977a5476fc7c45.tar.bz2 |
add auto_sbitmap class
gcc/ChangeLog:
2016-07-26 Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
* sbitmap.h (auto_sbitmap): New class.
From-SVN: r238747
-rw-r--r-- | gcc/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/sbitmap.h | 25 |
2 files changed, 29 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cbb70a7..79f79eb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2016-07-26 Trevor Saunders <tbsaunde+gcc@tbsaunde.org> + + * sbitmap.h (auto_sbitmap): New class. + 2016-07-26 Alan Modra <amodra@gmail.com> PR target/72103 diff --git a/gcc/sbitmap.h b/gcc/sbitmap.h index c208171..bd734f9 100644 --- a/gcc/sbitmap.h +++ b/gcc/sbitmap.h @@ -256,4 +256,29 @@ 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 &); +#if __cplusplus >= 201103L + auto_sbitmap (auto_sbitmap &&); + auto_sbitmap &operator = (auto_sbitmap &&); +#endif + + /* The bitmap we are managing. */ + sbitmap m_bitmap; +}; + #endif /* ! GCC_SBITMAP_H */ |