我想返回一个std::function
其类型取决于我的函数模板的一个模板参数的类型。
// Return a function object whose type is directly dependent on F
template<typename F, typename Arg1, typename Arg2>
auto make_f2_call(Arg1&& arg1, Arg2&& arg2)
-> std::function<--what-goes-here?-->
{
return [arg1, arg2](F f) { return f(arg1, arg2); };
}
// Usage example, so that it's clearer what the function does:
...
typedef bool (*MyFPtrT)(long id, std::string const& name);
bool testfn1(long id, std::string const& name);
...
auto c2 = make_f2_call<MyFPtrT>(i, n); // std::function<bool(F)>
...
bool result = c2(&testfn1);
逻辑上--what-goes-here?--
应该是函数的函数签名,该函数返回返回类型F
并采用类型参数,F
但我似乎无法告诉我的编译器(Visual Studio 2010 Express)这个意图。(注意:在使用示例中,它将是std::function<bool(F)>
。)
(注意:我尝试过变体std::result_of<F>::type
但没有成功。)
这对 C++0x 可行吗?