[vte] lib: Add smart pointer for g_free()able things



commit 27804390ee936ae79b973f3128db1d88b137710c
Author: Christian Persch <chpe src gnome org>
Date:   Tue Feb 4 18:13:47 2020 +0100

    lib: Add smart pointer for g_free()able things

 src/glib-glue.hh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/src/glib-glue.hh b/src/glib-glue.hh
index cbf7559e..379e36ce 100644
--- a/src/glib-glue.hh
+++ b/src/glib-glue.hh
@@ -26,6 +26,24 @@
 
 namespace vte::glib {
 
+template<typename T>
+using free_ptr = std::unique_ptr<T, decltype(&g_free)>;
+
+template<typename T>
+free_ptr<T>
+take_free_ptr(T* ptr)
+{
+        return {ptr, &g_free};
+}
+
+using string_ptr = free_ptr<char>;
+
+inline string_ptr
+take_string(char* str)
+{
+        return take_free_ptr(str);
+}
+
 class Error {
 public:
         Error() = default;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]