From 4f9c154d1a9df41dc3d97e443a687ffce228066b Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 16 Apr 2022 13:07:46 +0300 Subject: [PATCH] utils: add deletable_unique_ptr --- lib/utils/mu-utils.hh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh index 16a0f1ce..bea94186 100644 --- a/lib/utils/mu-utils.hh +++ b/lib/utils/mu-utils.hh @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -190,6 +191,19 @@ from_gchars(gchar*&& str) return s; } +// https://stackoverflow.com/questions/19053351/how-do-i-use-a-custom-deleter-with-a-stdunique-ptr-member +template +struct deleter_from_fn { + template + constexpr void operator()(T* arg) const { + fn(arg); + } +}; +template +using deletable_unique_ptr = std::unique_ptr>; + + + using Clock = std::chrono::steady_clock; using Duration = Clock::duration; @@ -283,7 +297,6 @@ to_string(const T& val) return sstr.str(); } - /** * Like std::find_if, but using sequence instead of a range. *