[vte/wip/systemd: 1/4] lib: Add smart pointer for g_free()able things



commit 3ce36d56b04f65e4d8d7596f82df939efb08a7f4
Author: Christian Persch <chpe src gnome org>
Date:   Sun Feb 2 23:16:16 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]