36 #include <type_traits> 56 template<
typename R,
typename B,
typename C,
typename... Args>
57 auto BindMemFn (R (B::*fn) (Args...), C *c)
59 static_assert (std::is_base_of<B, C> {},
"Base class where the member pointer belongs must be convertible to the binded object's class.");
60 return [fn, c] (Args... args) {
return (c->*fn) (args...); };
63 template<
typename R,
typename B,
typename C,
typename... Args>
64 auto BindMemFn (R (B::*fn) (Args...)
const,
const C *c)
66 static_assert (std::is_base_of<B, C> {},
"Base class where the member pointer belongs must be convertible to the binded object's class.");
67 return [fn, c] (Args... args) {
return (c->*fn) (args...); };
70 template<
typename R,
typename B,
typename C,
typename... Args>
71 std::function<R (Args...)>
BindMemFn (R (B::*fn) (Args...), C *c)
73 static_assert (std::is_base_of<B, C> {},
"Base class where the member pointer belongs must be convertible to the binded object's class.");
74 return [fn, c] (Args... args) {
return (c->*fn) (args...); };
77 template<
typename R,
typename B,
typename C,
typename... Args>
78 std::function<R (Args...)>
BindMemFn (R (B::*fn) (Args...)
const,
const C *c)
80 static_assert (std::is_base_of<B, C> {},
"Base class where the member pointer belongs must be convertible to the binded object's class.");
81 return [fn, c] (Args... args) {
return (c->*fn) (args...); };
88 template<
typename From>
91 return To { std::forward<From> (from) };
94 template<
typename From>
typename std::enable_if< B, T >::type EnableIf_t
std::function< R(Args...)> BindMemFn(R(B::*fn)(Args...), C *c)
Binds an instance of an object to its member function.
EnableIf_t<!std::is_base_of< To, Decay_t< From > >::value, To > operator()(From &&from) const