-
Notifications
You must be signed in to change notification settings - Fork 3
/
cfn_util.h
65 lines (52 loc) · 1.17 KB
/
cfn_util.h
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include <functional>
#include <vector>
template <typename FnType>
struct CFnGen {
public:
typedef std::function<FnType>* heap_fn;
private:
std::vector<std::function<FnType>*> heap_fns;
public:
CFnGen() {}
std::function<FnType>* wrap(std::function<FnType> fn) {
std::function<FnType>* ret(new std::function<FnType>(fn));
heap_fns.push_back(ret);
return ret;
}
~CFnGen() {
for(std::function<FnType>* fn : heap_fns) {
delete fn;
}
heap_fns.clear();
}
//copy
CFnGen(const CFnGen& o) {
for(std::function<FnType>* fn : o.heap_fns) {
heap_fns.push_back(new std::function<FnType>(fn));
}
}
//copy assign
CFnGen& operator=(const CFnGen& o) {
for(std::function<FnType>* fn : heap_fns) {
delete fn;
}
heap_fns.clear();
for(std::function<FnType>* fn : o.heap_fns) {
heap_fns.push_back(new std::function<FnType>(fn));
}
}
//move
CFnGen(CFnGen&& o) {
heap_fns = o.heap_fns;
o.heap_fns.clear();
}
//move assign
CFnGen& operator=(CFnGen&& o) {
for(std::function<FnType>* fn : heap_fns) {
delete fn;
}
heap_fns = o.heap_fns;
o.heap_fns.clear();
}
};