summaryrefslogtreecommitdiff
path: root/lib/ptr.hpp
blob: 0b002853d3470428e0eb17a04bde9892ad815b83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)(Params...), void (*deleter)(Obj *), Args &&... args)
	{
		return wrapped_ptr<Obj> {factory(std::forward<Args>(args)...), deleter};
	}
};

#endif