30 #ifndef BIND_METHOD_HXX
31 #define BIND_METHOD_HXX
33 #include <type_traits>
43 template<
typename S=
void()>
46 template<
typename R,
typename... Args>
48 typedef R (*function_pointer)(
void *
instance, Args... args);
51 function_pointer
function;
61 :instance_(_instance), function(_function) {}
72 operator bool()
const {
73 return function !=
nullptr;
77 return function(instance_, std::forward<Args>(args)...);
91 template<
typename T,
typename S>
94 template<
typename T,
typename R,
typename... Args>
96 typedef R (T::*method_pointer)(Args...);
107 template<
typename R,
typename T,
typename... Args>
128 template<
typename R,
typename... Args>
130 typedef R (*function_pointer)(
void *
instance, Args...);
143 template<
typename T,
typename M, M method,
typename R,
typename... Args>
145 static R
Invoke(
void *_instance, Args... args) {
146 auto &t = *(T *)_instance;
147 return (t.*method)(std::forward<Args>(args)...);
159 template<
typename T,
typename M, M method,
typename S>
162 template<
typename T,
typename M, M method,
typename R,
typename... Args>
167 template<
typename T,
typename S,
185 template<
typename T,
typename S,
191 BindMethodDetail::MakeBindMethodWrapper<T, S, method>());
198 #define BIND_METHOD(instance, method) \
199 BindMethod<typename BindMethodDetail::MethodSignatureHelper<decltype(method)>::class_type, \
200 typename BindMethodDetail::MethodSignatureHelper<decltype(method)>::plain_signature, \
207 #define BIND_THIS_METHOD(method) BIND_METHOD(*this, &std::remove_reference<decltype(*this)>::type::method)
Generate a wrapper function.
R operator()(Args...args) const
BoundMethod(std::nullptr_t)
Construct an "undefined" object.
Generate a wrapper function.
This object stores a function pointer wrapping a method, and a reference to an instance of the method...
Helper class which converts a signature type to a method pointer type.
Helper class which converts a plain function signature type to a wrapper function pointer type...
Helper class which introspects a method pointer type.
T class_type
The class which contains the given method (signature).
R plain_signature(Args...)
A function type which describes the "plain" function signature.
constexpr BoundMethod< S > BindMethod(T &_instance)
Construct a BoundMethod instance.
static R Invoke(void *_instance, Args...args)
constexpr BoundMethod(void *_instance, function_pointer _function)
MethodWrapperWithSignature< S >::function_pointer MakeBindMethodWrapper()