我正在尝试创建一个可延迟的调用对象。类似于(伪代码)的东西:
template <class FN>
struct delayable_call
{
return-type-of-FN call(); // <-- I'd like to use result_of here.
template<class ArgTypes...>
delayable_call(FN* pFn, ArgTypes... args);
FN* fn;
args-saving-struct;
};
我尝试使用 result_of::type 作为调用的返回类型,但在模板的实例化过程中出现错误,因为显然需要单独指定参数类型。
实例化:
int foo(bool, double); // function prototype.
delayable_call<int(bool, double)> delayable_foo(foo, false, 3.14); // instantiation
我读过的有关 result_of 的错误消息和文档似乎表明还必须指定参数类型。因此result_of<FN>::type
,我需要指定result_of<FN(bool, double)>::type
. 这确实解决了我遇到的编译问题,但打破了模板的通用性。
那么,当模板参数表示函数签名时,如何将 result_of 与模板参数一起使用?