diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-01-17 18:54:26 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-01-17 18:54:26 +0000 |
commit | 43a87590f45aa6e55724d30d0c2d0d34b407a57e (patch) | |
tree | 21ce8e8886f8aa58b159419b7d885f57d9a37580 /ptr.hpp | |
parent | Initial commit (diff) | |
download | ilt-43a87590f45aa6e55724d30d0c2d0d34b407a57e.tar.bz2 ilt-43a87590f45aa6e55724d30d0c2d0d34b407a57e.tar.xz ilt-43a87590f45aa6e55724d30d0c2d0d34b407a57e.zip |
First cut modernizing and sanitizing
Diffstat (limited to 'ptr.hpp')
-rw-r--r-- | ptr.hpp | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -0,0 +1,25 @@ +#ifndef PTR_H +#define PTR_H + +#include <memory> + +template<typename Obj> class wrapped_ptr : public std::unique_ptr<Obj, void (*)(Obj *)> { +public: + using std::unique_ptr<Obj, void (*)(Obj *)>::unique_ptr; + wrapped_ptr() : std::unique_ptr<Obj, void (*)(Obj *)> {{}, {}} { } + + inline + operator Obj *() const + { + return this->get(); + } + + template<typename... Args, typename... Params> + static auto + create(Obj * (*factory)(Args...), void (*deleter)(Obj *), Params &&... params) + { + return wrapped_ptr<Obj> {factory(std::forward<Params>(params)...), deleter}; + } +}; + +#endif |