From d63f5ce1cb86e69da28bd74b21e9452dbd88a38f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 28 Feb 2021 15:42:39 +0000 Subject: Move utility to lib --- lib/ptr.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/ptr.hpp (limited to 'lib/ptr.hpp') diff --git a/lib/ptr.hpp b/lib/ptr.hpp new file mode 100644 index 0000000..b92b63e --- /dev/null +++ b/lib/ptr.hpp @@ -0,0 +1,25 @@ +#ifndef PTR_H +#define PTR_H + +#include + +template class wrapped_ptr : public std::unique_ptr { +public: + using std::unique_ptr::unique_ptr; + wrapped_ptr() : std::unique_ptr {{}, {}} { } + + inline + operator Obj *() const + { + return this->get(); + } + + template + static auto + create(Obj * (*factory)(Args...), void (*deleter)(Obj *), Params &&... params) + { + return wrapped_ptr {factory(std::forward(params)...), deleter}; + } +}; + +#endif -- cgit v1.2.3