5,530
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
template <typename Functor>
class RunnableAdapter;
template <typename R>
class RunnableAdapter<R(*)()> {
public:
typedef R (RunType)();
explicit RunnableAdapter(R(*function)())
:function_(function) {
}
R Run() {
return function_();
}
private:
R(*function_)();
};
template <typename T>
struct FunctorTraits {
typedef RunnableAdapter<T> RunnableType;
typedef typename RunnableType::RunType RunType;
};
template <typename Functor>
void Bind(Functor functor) {
typedef typename FunctorTraits<Functor>::RunnableType RunnableType;
typedef typename FunctorTraits<Functor>::RunType RunType;
RunnableType r(functor);
r.Run();
};
void func()
{
printf("call func\n");
}
int main()
{
Bind(func);
return 0;
}