diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-28 15:42:39 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-28 15:42:39 +0000 |
commit | d63f5ce1cb86e69da28bd74b21e9452dbd88a38f (patch) | |
tree | 0c9495f8cb5af05e6068b69d5d57551cc2331a97 /lib/ptr.hpp | |
parent | Just use addLinksBetween (diff) | |
download | ilt-d63f5ce1cb86e69da28bd74b21e9452dbd88a38f.tar.bz2 ilt-d63f5ce1cb86e69da28bd74b21e9452dbd88a38f.tar.xz ilt-d63f5ce1cb86e69da28bd74b21e9452dbd88a38f.zip |
Move utility to lib
Diffstat (limited to 'lib/ptr.hpp')
-rw-r--r-- | lib/ptr.hpp | 25 |
1 files changed, 25 insertions, 0 deletions
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 <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 |