[vte/wip/systemd: 1/3] 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/3] lib: Add smart pointer for g_free()able things
- Date: Sun, 2 Feb 2020 19:16:15 +0000 (UTC)
commit c41ca7b51d278240f6eb26d66bb046619c89ff7f
Author: Christian Persch <chpe src gnome org>
Date: Sun Feb 2 20:11:25 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]