【发布时间】:2020-12-17 20:44:33
【问题描述】:
template<class Fn, class ...Args>
class func_class<Fn(Args...)> // Do not know what to do here
{
typedef typename result_of<Fn(Args...)>::type mytype;
std::function<mytype(Args...)> func_;
std::tuple<Args...> tuple1;
public:
func_class(Fn&& func_in, Args&& ...args)
{
func_ = func_in;
tuple1 = make_tuple(args...);
}
mytype
exe ()
{
mytype ret;
ret = apply(func_, tuple1);
return ret;
}
};
int func(int a) {return a;}
int main () {
// return type of "func" can be deduced by "result_of<decltype(func)&(int)>::type"
// And result_of is declared as "result_of<Fn(Args...)>"
// Want func_class to have the same interface
func_class<decltype(func)&(int)> fc; // Want to declare a object like this
fc.exe();
}
代码如上。 func 的返回类型可以由result_of<decltype(func)&(int)>::type 推导出来。并且result_of 被声明为result_of<Fn(Args...)>。
想让func_class拥有和result_of一样的界面。
编译器抱怨如下:
test.cpp:211:7: error: 'func_class' is not a class template
我能做什么? 提前谢谢你。
【问题讨论】: