I'd like to write a function which can both take a function or a method as parameter. ie a function accepting the same parameter than the std::thread
constructor.
So far I have something working for a function but have hard time for methods:
template<typename F, typename... Args>
typename std::result_of<typename std::decay<F>::type(typename std::decay<Args>::type...)>::type
call(F &&func, Args... args) {
return func(args...);
}
void hello() { std::cout << "hello\n"; }
class Hello {
public:
Hello() = default;
~Hello() = default;
void hello() { std::cout << "hello\n"; }
};
int main()
{
// func
call(hello);
// meth
Hello h;
call(&Hello::hello, &h);
}
I tried to reproduce what is done by the contructor of std::thread
but struggle to find the right way to write it.