diff options
author | Christian Persch <chpe@src.gnome.org> | 2020-02-04 18:13:47 +0100 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2020-02-04 18:13:47 +0100 |
commit | 27804390ee936ae79b973f3128db1d88b137710c (patch) | |
tree | ae01935c92073c30a85e5b679eb55e4145fa384f | |
parent | c4f90c53cb1f2267eb7b7de9dc834ac17720f51b (diff) | |
download | vte-27804390ee936ae79b973f3128db1d88b137710c.tar.gz |
lib: Add smart pointer for g_free()able things
-rw-r--r-- | src/glib-glue.hh | 18 |
1 files changed, 18 insertions, 0 deletions
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; |