-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.hpp
78 lines (68 loc) · 1.17 KB
/
function.hpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef FUNCTION_HPP_INCLUDED
#define FUNCTION_HPP_INCLUDED
template <typename> class Function;
template <typename R>
class Function<R()>
{
public:
typedef R (*function_type)();
Function(function_type func)
: func_(func)
{
}
R operator()()
{
return func_();
}
private:
function_type func_;
};
template <typename R, typename A1>
class Function<R(A1)>
{
public:
typedef R (*function_type)(A1);
Function(function_type func)
: func_(func)
{
}
R operator()(A1 a1)
{
return func_(a1);
}
private:
function_type func_;
};
template <typename R, typename A1, typename A2>
class Function<R(A1, A2)>
{
public:
typedef R (*function_type)(A1, A2);
Function(function_type func)
: func_(func)
{
}
R operator()(A1 a1, A2 a2)
{
return func_(a1, a2);
}
private:
function_type func_;
};
template <typename R, typename A1, typename A2, typename A3>
class Function<R(A1, A2, A3)>
{
public:
typedef R (*function_type)(A1, A2, A3);
Function(function_type func)
: func_(func)
{
}
R operator()(A1 a1, A2 a2, A3 a3)
{
return func_(a1, a2, a3);
}
private:
function_type func_;
};
#endif // !defined(FUNCTION_HPP_INCLUDED)