1 #ifndef _bound_method__hpp__included__
2 #define _bound_method__hpp__included__
6 template<typename ret
, typename
... args
>
7 class bound_method_base
;
9 template<typename ret
, typename
... args
>
17 bound_method(bound_method_base
<ret
, args
...>& method
)
30 bound_method
& operator=(const bound_method
& m
)
32 if(target
== m
.target
)
44 bool operator==(const bound_method
& m
)
46 return (target
== m
.target
);
48 bool operator!=(const bound_method
& m
)
50 return (target
!= m
.target
);
63 return (target
!= NULL
);
67 return (target
== NULL
);
69 bound_method(const bound_method
& m
)
75 ret
operator()(args
... arg
)
78 throw std::runtime_error("Attempted to call null pointer");
79 return (*target
)(arg
...);
82 bound_method_base
<ret
, args
...>* target
;
85 template<typename ret
, typename
... args
>
86 class bound_method_base
89 virtual ~bound_method_base()
92 virtual ret
operator()(args
... arg
) = 0;
95 friend class bound_method
<ret
, args
...>;
98 template<class T
, typename ret
, typename
... args
>
99 class bound_method_deriv_class
: public bound_method_base
<ret
, args
...>
102 bound_method_deriv_class(T
& _object
, ret (T::*_fun
)(args
... arg
))
103 : object(_object
), fun(_fun
)
106 ret
operator()(args
... arg
)
108 return (object
.*fun
)(arg
...);
112 ret (T::*fun
)(args
... arg
);
115 template<typename ret
, typename
... args
>
116 class bound_method_deriv_fun
: public bound_method_base
<ret
, args
...>
119 bound_method_deriv_fun(ret (*_fun
)(args
... arg
))
123 ret
operator()(args
... arg
)
128 ret (*fun
)(args
... arg
);
131 template<typename ret
, typename tail
, typename
... args
>
132 class bound_method_bind_tail
: public bound_method_base
<ret
, args
...>
135 bound_method_bind_tail(bound_method
<ret
, args
..., tail
> _fn
, tail _t
)
141 ret
operator()(args
... arg
)
143 return fn(arg
..., t
);
146 bound_method
<ret
, args
..., tail
> fn
;
150 template<class T
, typename ret
, typename
... args
>
151 bound_method
<ret
, args
...> make_bound_method(T
& _object
, ret (T::*_fun
)(args
... arg
))
153 return bound_method
<ret
, args
...>(*new bound_method_deriv_class
<T
, ret
, args
...>(_object
, _fun
));
156 template<typename ret
, typename
... args
>
157 bound_method
<ret
, args
...> make_bound_method(ret (*_fun
)(args
... arg
))
159 return bound_method
<ret
, args
...>(*new bound_method_deriv_fun
<ret
, args
...>(_fun
));
162 template<typename ret
, typename tail
, typename
... args
>
163 bound_method
<ret
, args
...> bind_last(bound_method
<ret
, args
..., tail
> fn
, tail t
)
165 return bound_method
<ret
, args
...>(*new bound_method_bind_tail
<ret
, tail
, args
...>(fn
, t
));