【发布时间】:2016-04-25 18:45:35
【问题描述】:
有没有办法从模板类中提取 typedef?例如,这是我想做的:
template<typename T, typename... Args>
class Foo{
public:
typedef T(*Functor)(Args...);
Foo() = default;
};
template<typename T, typename... Args>
Foo<T, Args...> make_foo(T(*f)(Args...)){
return Foo<T, Args...>;
}
int bar(int i){
return i * 2;
}
using type = make_foo(bar)::Functor;
我不能这样做。但是,我可以这样做:
using type = Foo<int, int>::Functor;
这种方式违背了我的目的。有什么方法可以包装一个函数,以便我可以以类型形式提取它?
【问题讨论】:
标签: c++ templates types casting