Horizon
src
util
autofree_ptr.hpp
1
#pragma once
2
#include <functional>
3
4
namespace
horizon {
5
template
<
typename
T>
class
autofree_ptr
{
6
public
:
7
autofree_ptr
(T *p, std::function<
void
(T *)> ffn) : ptr(p), free_fn(ffn)
8
{
9
}
10
autofree_ptr
(std::function<
void
(T *)> ffn) : free_fn(ffn)
11
{
12
}
13
T *ptr =
nullptr
;
14
std::function<void(T *)> free_fn;
15
16
T &operator*()
17
{
18
return
*ptr;
19
}
20
21
T *operator->()
const
22
{
23
return
ptr;
24
}
25
26
operator
T *()
const
27
{
28
return
ptr;
29
}
30
31
~
autofree_ptr
()
32
{
33
free_fn(ptr);
34
}
35
};
36
}
// namespace horizon
horizon::autofree_ptr
Definition:
autofree_ptr.hpp:5
Generated by
1.8.16