[vte/wip/systemd: 1/5] lib: Add smart pointer for g_free()able things
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/wip/systemd: 1/5] lib: Add smart pointer for g_free()able things
- Date: Tue, 4 Feb 2020 15:10:51 +0000 (UTC)
commit 62c0927e38f9de05588f15b28b3f1dcffae9b478
Author: Christian Persch <chpe src gnome org>
Date: Tue Feb 4 16:10:26 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]